Cookie 不保值?
可能的重复:
为什么我的 cookie 没有设置?
我有以下函数来设置 Cookie和两个会话:
function validateUser($username) {
session_regenerate_id ();
$_SESSION['valid'] = 1;
$_SESSION['username'] = $username;
setcookie('username2',$username,time()+60*60*24*365,'/');
header("Location: ../new.php");
exit();
}
调用函数时:
if(mysql_num_rows($queryreg) != 0){
$row = mysql_fetch_array($queryreg,MYSQL_ASSOC);
$hash = hash('sha256', $row['salt'] . hash('sha256', $password));
if($hash == $row['password']) {
if($row['confirm'] == 1){
if(isset($remember)){
setcookie('username',$username,time()+60*60*24*365,'/');
setcookie('password',$password,time()+60*60*24*365,'/');
} else {
setcookie('username','',time()-3600,'/');
setcookie('password','',time()-3600,'/');
}
validateUser($username);
但是,在 test.php
上,我添加了 echo $_COOKIE['username2']; exit();
用于调试目的。然而,cookie 每次都会以 Jason(两个用户之一)的身份出现。无论谁登录。
希望这是有道理的。
Possible Duplicate:
Why are my cookies not setting?
I have the following function to set a Cookie and two Sessions:
function validateUser($username) {
session_regenerate_id ();
$_SESSION['valid'] = 1;
$_SESSION['username'] = $username;
setcookie('username2',$username,time()+60*60*24*365,'/');
header("Location: ../new.php");
exit();
}
When the function is called:
if(mysql_num_rows($queryreg) != 0){
$row = mysql_fetch_array($queryreg,MYSQL_ASSOC);
$hash = hash('sha256', $row['salt'] . hash('sha256', $password));
if($hash == $row['password']) {
if($row['confirm'] == 1){
if(isset($remember)){
setcookie('username',$username,time()+60*60*24*365,'/');
setcookie('password',$password,time()+60*60*24*365,'/');
} else {
setcookie('username','',time()-3600,'/');
setcookie('password','',time()-3600,'/');
}
validateUser($username);
However, on test.php
I added echo $_COOKIE['username2']; exit();
for debugging purposes. However, the cookie comes up as jason, one of the two users, every time. No matter who is logged in.
Hope this makes sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要忘记
在你的 new.php 中
调用你的
函数
Do not forgot to
in your new.php
and to call your
function