开发者

setcookie PHP doesn't work in a right way

开发者 https://www.devze.com 2023-03-02 17:54 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号