我正在为我的新网站使用 cookie,但我遇到了这个问题: 如果我在
上用我的脚本设置一个 cookieserver.dom/scripts/addcookie.php
它会保存我的 cookie 但在
上不可用server.dom/index.php
我相信我的问题是由路径引起的。 知道如何让它全局化吗? 谢谢
最佳答案
来自 the documentation :
bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )
path
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
因此将第 4 个参数设置为 setcookie
为 '/'
关于php - 如何在每个页面中使 PHP cookie 全局化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21496457/