Search code examples
phpcookiessession-cookiessetcookie

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


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


Solution

  • 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.