简体   繁体   English

setcookie PHP 无法正常工作

[英]setcookie PHP doesn't work in a right way

I have such situation: I do setcookie("bla",md5("bla"),time()+36000) .我有这样的情况:我做setcookie("bla",md5("bla"),time()+36000) After this I do see this cookie in the browser but If I will write print_r($_COOKIE) on the server - there will be not exist cookie with key "bla".在此之后,我确实在浏览器中看到了这个 cookie,但是如果我在服务器上写print_r($_COOKIE) - 将不存在键为“bla”的 cookie。 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. $_COOKIE是包含在 HTTP 请求中传递的信息的超级全局变量之一。 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() .您只会在已经拥有 cookie 的浏览器发出请求时看到它,而不是在调用setcookie()之后直接看到它。

Also, in your code example, you appear to be trying to concat using the + operator:此外,在您的代码示例中,您似乎正在尝试使用+运算符进行连接:

$result['user_password']+"solt"

PHP uses the . PHP 使用. operator for concat.连接运算符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM