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

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

I am developing a local XAMPP testing server. Is there a parameter that I have to change to PHP.ini or is this the usual behavior for cookies? Sorry, I'm a little new to this material, and I was impressed that cookies were available throughout the site.

I set cookies as:

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

Any help would be greatly appreciated. Thanks

+7
source share
1 answer

Try setting the cookie path to the root:

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

Also it is in the same domain? Access via HTTPS will also affect your cookies.

+11
source

All Articles