简体   繁体   English

为什么此PHP setcookie()参数未设置cookie?

[英]Why does this PHP setcookie() argument not set a cookie?

I have this PHP 我有这个PHP

setcookie('hello', '0', 0, '/389732/');

Why when I run it does it not set a cookie? 为什么当我运行它时不设置cookie?

I printed the value of $_COOKIE['hello'] out immediately after and it puts out an error because it does not exist. 之后,我立即打印出$_COOKIE['hello']的值,由于不存在错误,它发出了一个错误。

setcookie documentation spells this out: setcookie文档对此进行了说明:

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE ... 设置cookie后,可以使用$ _COOKIE 在下一页加载时访问它们。

Edit: it might be tempting to manually insert that cookie into $_COOKIE yourself, but keep in mind that some frameworks helpfully parse $_COOKIE into other data structures on startup and will not see such hackish changes. 编辑:自己将cookie手动插入$_COOKIE可能很诱人,但请记住,某些框架在启动时会帮助将$_COOKIE解析为其他数据结构,并且不会看到这样的改动。

$_COOKIE gets populated when the script first runs. 脚本首次运行时,将填充$ _COOKIE。 setcookie puts the cookie info in a queue that gets turned into a header when the page returns to the browser. setcookie将cookie信息放入队列中,当页面返回到浏览器时,该队列将变成标题。

When the browser requests a new page, it sends the cookie information back to your server and the $_COOKIE variable will be populated. 当浏览器请求一个新页面时,它将cookie信息发送回您的服务器,然后将填充$ _COOKIE变量。

因为$ _COOKIE是调用php时cookie的内容。

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

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