php - 如何在每个页面中使 PHP cookie 全局化

标签 php cookies

我正在为我的新网站使用 cookie,但我遇到了这个问题: 如果我在

上用我的脚本设置一个 cookie

server.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/

相关文章:

php - 在 MySQL 数据库中发现更改时更新 HTML

asp.net - 攻击aspx网站的方法

javascript - 如何使用文档和Request.Cookies

javascript - 是否可以判断 GWT 中是否启用了 cookie?如果不是,什么原生 JavaScript 可以做到这一点?

php - 使用 id 为不同的列排序

php - 没有数据库的 Codeigniter 网站在实时服务器上生成数据库错误

javascript - 如何使用 cookie 或本地存储将类添加到子菜单的父级

javascript - 如何通过javascript更新asp.net中现有的cookie

php - Mail::send Laravel 中的语法错误

php - Yii2:数字格式