Cookies don't maintain value? [duplicate]
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);
$ha开发者_高级运维sh = 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.
Do not forgot to
session_start()
in your new.php
and to call your
validateUser()
function
精彩评论