Cookie 在不同页面上不起作用

2021-12-21 00:00:00 cookies php

好的,我有一个 cookie 集,如果我在 Firefox 中访问私人数据,我可以清楚地看到它……好的,所以当我在某个目录的一页上回显它时,它可以工作,(www.example.com/dir),但在站点(www.example.com)的索引页面上,它不会回显,它说没有设置cookie.是的,我启用了 cookie,是的,我尝试清除缓存等等.有任何想法吗?PHP 顺便说一句

Ok I have a cookie set, and I can clearly see it if I go to private data in Firefox... ok so when I echo it on one page in a certain directory it works, (www.example.com/dir), but on the index page of the site (www.example.com), it wont echo, it says the cookie is not set. Yes I have cookies enabled, yes I tried clearing cache and all that. Any ideas? PHP btw

推荐答案

设置 cookie 时您在哪个目录?

Which directory are you in when the cookie gets set?

来自 PHP 手册 setcookie(),强调我的:

路径

cookie 可用的服务器上的路径.如果设置为/",cookie 将在整个域中可用.如果设置为 '/foo/',则 cookie 将仅在/foo/目录和域的所有子目录(例如/foo/bar/)中可用.默认值是设置 cookie 的当前目录.

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.

相关文章