从Header()中的URL字符串传递Parameter重定向到PHP中的另一个页面


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

我想将URL字符串数据从login.php传递到dashboard.php这里我只有一个登录身份验证,而URL中的数据是通过URL字符串从homepage.php表单传递到登录的,我想将此字符串传递到仪表板

从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,并在dashboardphp上显示这些数据。注意,我在登录时只有用户id pass-auth,其中URL链接携带来自homepage.php的数据。

登录时,当重定向到仪表板时,您的URL是

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

这些变量并不存在。您需要使用$_GET['name_']等,url 中使用的名称