setcookie PHP doesn't work in a right way
I have such situation: I do setcookie("bla",md5("bla"),time()+36000)
.
After this I do see this cooki开发者_开发技巧e in the browser but If I will write print_r($_COOKIE)
on the server - there will be not exist cookie with key "bla". Any ideas?
here is the listing:
setcookie("login_cookie",md5($result['user_password']."solt"),time()+36000);
setcookie("login_info",$result['user_id'],time()+36000);
header("Location:{$_SERVER['HTTP_REFERER']}");
exit();
Try the following (set the path argument to the root):
setcookie("login_cookie",md5($result['user_password']."solt"),time()+36000, '/');
setcookie("login_info",$result['user_id'],time()+36000, '/');
I have a feeling you're going out to a different directory in the redirect which is why it's not displayed, of course, I may be wrong.
$_COOKIE
is one of the super globals which contain information passed in the HTTP request. You will only see it when a request has been made by a browser which already has the cookie, not directly after having called setcookie()
.
Also, in your code example, you appear to be trying to concat using the +
operator:
$result['user_password']+"solt"
PHP uses the .
operator for concat.
精彩评论