I have a cookie that I've set on my site called "your-selected-location". I'm in FF and using firebug I can see that the cookie is set seemingly correctly and does not expire until next year and is stored in the root "/". However if I run the following code in very top of my PHP file it does not return the cookie value (which I can see in Firebug)
if (isset($_COOKIE[ 'your-selected-location' ]))
{
$cookieselectedlocation = $_COOKIE['your-selected-location'];
echo ("<hr>Your cookie is: $cookieselectedlocation<hr>");
}
I've also tried a direct echo:
echo $_COOKIE[ 'your-selected-location' ];
With no luck. Any thoughts? Thanks!
Chris
EDIT: Here's where it gets weirder: www.site.com/merchant_profile --> Cannot read cookies site.com/merchant_profile --> CAN read cookies
OK, problems solved. The www.site.com vs. site.com led me to another stack overflow post that explains it all: PHP cookie problem - www or without www
you should set cookies with setcookie()
setcookie('your-selected-location', 'New York');
When you set a cookie with setcookie() it's not in the $_COOKIE array until the next page load, but it still makes it to the browser.