My cookies are only available on PHP pages they are set on, is this normal?

故事扮演 提交于 2019-12-06 01:30:06

问题


I cannot access cookies from any page other than the page they are set on. I looked at print_r($_COOKIE) on different pages and the only common variable between pages is the $_COOKIE['PHPSESSID'].

I am developing on a local XAMPP testing server. Is there a setting I should change on the PHP.ini or is this normal behavior for cookies? Sorry, I'm a little new to this stuff and I was under the impression cookies were accessible site wide.

I am setting cookies like:

setcookie("user", "Dave Schmave", time()+60*60*24*120);

Any help would be greatly appreciated. Thanks


回答1:


Try setting the cookie path to the root:

setcookie("user", "Dave Schmave", time()+60*60*24*120, '/');

Also is it on the same domain? Accessing via HTTPS will also affect your cookies.



来源:https://stackoverflow.com/questions/9679313/my-cookies-are-only-available-on-php-pages-they-are-set-on-is-this-normal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!