簡體   English   中英

從Header()中的URL字符串傳遞參數重定向到PHP中的另一個頁面

[英]Passing Parameter from URL string in Header() redirect to another page in PHP

我想將URL字符串數據從login.php傳遞到dashboard.php,這里我只有一個登錄身份驗證,而URL中存在的數據是從homepage.php表單攜帶通過URL字符串登錄的,我想將其繼續進行字符串到儀表板

從dashboard.php重定向的代碼用於登錄會話以進行登錄:

<?php
if(!$_SESSION["UserName"])
{
    //Do not show protected data, redirect to login...
     $FullName = $_REQUEST["name_"]; 
     $Subject = $_REQUEST["subject_"];
     $Phone = $_REQUEST["phone_"];
     $Email = $_REQUEST["email_"];
     $Message = $_REQUEST["message_"];
    header("Location: login.php?name_=$FullName&subject_=$Subject&phone_=$Phone&email_=$Email&message_=$Message");

}

?>

重定向后顯示在login.php中的URL字符串:

http://localhost/youngants/login.php?name_=Sharayu%20Bhave&subject_=hello&phone_=9876543210&email_=bhave.sharayu@gmail.com&message_=hh

用戶登錄並重定向到dashbord.php后,我得到一個空白URL字符串,並且不顯示數據,請參見以下內容:

http://localhost/youngants/dashboard.php?name_=&subject_=&phone_=&email_=&message_=

我的登錄代碼中,我再次通過header()傳遞了相同的URL,請參見下文:-

if(isset($_POST['login']))  
                                    {  
                                        $username=$_POST['Username'];  
                                        $user_pass=$_POST['password'];  
                                        $encrypt_pass = md5($user_pass);


                                        $check_user="select * from tbl_logindetails WHERE UserName='".$username."' AND Password='".$encrypt_pass."'";
                                        $run=mysqli_query($connection,$check_user); 



    if(mysqli_num_rows($run))  
                                            {  
                                                //echo "<script>window.open('www.google.com','_self')</script>"; 
                                                header("Location: dashboard.php?name_=$FullName&subject_=$Subject&phone_=$Phone&email_=$Email&message_=$Message");                                  

                                                $_SESSION['UserName']= $username; //here session is used and value of $user_email store in $_SESSION.  


                                            }  
                                            else 
                                            {  

                                              echo "<script>alert( 'Error in Registering Useer, Please try again later' )</script>";  
                                            }  
                                        }  

我從中獲取數據的HTML表單:-

 <form class="form ajax-contact-form" method="" action="dashboard.php">
                            <div class="alert alert-success hidden" id="contact-success">
                                <span class="glyphicon glyphicon-ok "></span> &nbsp;
                                <strong>Success!</strong> Thank you for your message.
                            </div>
                            <div class="alert alert-danger hidden" id="contact-error">
                                <span class="glyphicon glyphicon-remove "></span> &nbsp;
                                <strong>Error!</strong> Oops, something went wrong.
                            </div>
                            <div class="row col-p10">
                                <div class="col-sm-6">
                                    <label class="mb10">
                                        <input type="text" name="name_" id="name_" required class="form-control" placeholder=" Full Name * ">


                                    </label>
                                </div>
                                <div class="col-sm-6">
                                    <label class="mb10">
                                        <input type="text" name="subject_" id="subject_" required class="form-control" placeholder=" Subject *">
                                    </label>
                                </div>
                            </div>
                            <div class="row col-p10">
                                <div class="col-sm-6">
                                    <label class="mb10">
                                        <input type="text" name="phone_" id="phone_" class="form-control" placeholder=" Phone">
                                    </label>
                                </div>
                                <div class="col-sm-6">
                                    <label class="mb10">
                                        <input type="email" name="email_" id="email_" required class="form-control" placeholder=" Email Address *">
                                    </label>
                                </div>
                            </div>
                            <label>
                                <textarea name="message_" id="message_" cols="30" rows="10" required class="form-control" placeholder=" Message *"></textarea>
                            </label>
                            <div class="mb40"></div>
                            <div class="clearfix">
                            <!-- Enter your google site key here for captcha -->
                               <div class="pull-right xs-pull-left xs-box">



                                </div>  
                                <div class="pull-left">
                                    <button type="submit" class="btn btn-icon btn-e" value="submit" name="submit"><i class="icon icon_mail_alt"></i> Sumbit</button>



                                </div>
                            </div>
                        </form>

我想要將上述URL從login.php帶回到dashboard.php,並在dashboard.php上顯示此數據。 請注意,我只有登錄時的用戶ID通過auth,URL鏈接攜帶了homepage.php中的數據。

登錄時,重定向到信息中心時,您的網址是

 header("Location: dashboard.php?name_=$FullName&subject_=$Subject&phone_=$Phone&email_=$Email&message_=$Message"); 

這些變量不存在。 您需要使用$_GET['name_']等,網址中使用的名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM