[英]Passing Parameter from URL string in Header() redirect to another page in PHP
I want to pass the URL string data to dashboard.php from login.php here I have just a login auth whereas the data present in the URL is been carried from homepage.php form to login via URL string, I want to carry forward this string to dashboard 我想将URL字符串数据从login.php传递到dashboard.php,这里我只有一个登录身份验证,而URL中存在的数据是从homepage.php表单携带通过URL字符串登录的,我想将其继续进行字符串到仪表板
The code which gets redirected from dashboard.php for login session for login: 从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");
}
?>
URL String shown in login.php after redirect: 重定向后显示在login.php中的URL字符串:
http://localhost/youngants/login.php?name_=Sharayu%20Bhave&subject_=hello&phone_=9876543210&email_=bhave.sharayu@gmail.com&message_=hh
After the user logs in and redirects to dashbord.php I get a blank URL string and data is not displayed, see below :- 用户登录并重定向到dashbord.php后,我得到一个空白URL字符串,并且不显示数据,请参见以下内容:
http://localhost/youngants/dashboard.php?name_=&subject_=&phone_=&email_=&message_=
My login code where I pass the same URL again via header(), see below :- 我的登录代码中,我再次通过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>";
}
}
My html form from which i take data :- 我从中获取数据的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>
<strong>Success!</strong> Thank you for your message.
</div>
<div class="alert alert-danger hidden" id="contact-error">
<span class="glyphicon glyphicon-remove "></span>
<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>
I want is to take the above URL from login.php back to dashboard.php and display this data there on dashboard.php. 我想要将上述URL从login.php带回到dashboard.php,并在dashboard.php上显示此数据。 Note, I have only the user id pass auth on login where the URL link carries data from homepage.php. 请注意,我只有登录时的用户ID通过auth,URL链接携带了homepage.php中的数据。
on login, when redirecting to dashboard your URL is 登录时,重定向到信息中心时,您的网址是
header("Location: dashboard.php?name_=$FullName&subject_=$Subject&phone_=$Phone&email_=$Email&message_=$Message");
those variables dont exist. 这些变量不存在。 you need to use $_GET['name_']
etc, the names used in the url 您需要使用$_GET['name_']
等,网址中使用的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.