标头重定向时未设置会话变量
我遇到的问题是我的会话变量未设置/保存。
这是我的代码:
index.php 有:
<? //this is first line of page
session_start();
?>
<form action="admin_process_login.php" method="post">
<p>EMAIL</p><input name="email" type="text">
<p>PASSWORD</p><input name="password" type="password" />
<input type="submit" value="Enter">
</form>
admin_process_login.php
<? //this is first line of page
session_start();
$useremail = $_POST['email'];
$postpassword = $_POST['password'];
include('admin_config.php');
if ($postpassword != "" && $useremail != "") {
//Connect to database
mysql_connect("localhost", $dbusr, $dbpass) or die(mysql_error());
mysql_select_db("studioel_dental") or die(mysql_error());
//Look for a matching email/password
$query = "SELECT *
FROM users
WHERE users.email = '$useremail'
AND users.password = '$postpassword'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if(mysql_num_rows($result)==0){
header("Location: http://www.dentalbenefitprogram.com/admin.php?error=nomatch");
} else {
//set session variables and load supplies page
$uid = $row['id'];
$unamex = $row['name'];
$uemailx = $row['email'];
$utypex = $row['type'];
$_SESSION['userid']=$uid;
$_SESSION['uname']=$unamex;
$_SESSION['uemail']=$uemailx;
$_SESSION['utype']=$utypex;
header("Location: http://www.dentalbenefitprogram.com/admin_groups.php");
exit;
};
} else {
//email or password fields were blank. Return to login page
header("Location: http://www.dentalbenefitprogram.com/admin.php?error=blank");
};
?>
您可能会猜到:会话变量没有被设置...
非常感谢任何帮助!
I'm having a problem where my session variables aren't getting set/saved.
Here is my code:
index.php has:
<? //this is first line of page
session_start();
?>
<form action="admin_process_login.php" method="post">
<p>EMAIL</p><input name="email" type="text">
<p>PASSWORD</p><input name="password" type="password" />
<input type="submit" value="Enter">
</form>
admin_process_login.php
<? //this is first line of page
session_start();
$useremail = $_POST['email'];
$postpassword = $_POST['password'];
include('admin_config.php');
if ($postpassword != "" && $useremail != "") {
//Connect to database
mysql_connect("localhost", $dbusr, $dbpass) or die(mysql_error());
mysql_select_db("studioel_dental") or die(mysql_error());
//Look for a matching email/password
$query = "SELECT *
FROM users
WHERE users.email = '$useremail'
AND users.password = '$postpassword'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if(mysql_num_rows($result)==0){
header("Location: http://www.dentalbenefitprogram.com/admin.php?error=nomatch");
} else {
//set session variables and load supplies page
$uid = $row['id'];
$unamex = $row['name'];
$uemailx = $row['email'];
$utypex = $row['type'];
$_SESSION['userid']=$uid;
$_SESSION['uname']=$unamex;
$_SESSION['uemail']=$uemailx;
$_SESSION['utype']=$utypex;
header("Location: http://www.dentalbenefitprogram.com/admin_groups.php");
exit;
};
} else {
//email or password fields were blank. Return to login page
header("Location: http://www.dentalbenefitprogram.com/admin.php?error=blank");
};
?>
You can probably guess: the session variables aren't being set...
Any help is appreciated greatly!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Brian:
我的猜测是,在第一行的评论之前,有一个空格导致了这个问题。
PHP 手册提醒用户注意这一点:
此外,您可能需要考虑使用长标签而不是短标签。
最好的
Brian:
My guess is that before your comment in the first line you have a space that is causing this problem.
PHP manual cautions users to watch out for this:
Also, you may want to consider using long tags instead of short tags.
Best
在代码的最开头使用
ob_start();
&不要忘记在代码的最末端添加
ob_end_flush();
use
ob_start();
at the extreme beginning of ur code& dont forget to add
ob_end_flush();
at the extreme end of ur code