Magento 1 – Cookie Bug with WebKit Based Browsers

cookiemagento-1

There is a reasonably common & well documented cookie-related bug/issue with Magento and Chrome (looking at the others' issues – possibly WebKit and IE at times). Whether this is due to a common Chrome extension/setting or incorrect web server setting – I do not know.

I'm on OS X 10.8.2 running CentOS 5.8 via VirtualBox. More often than not, for me to login to a Magento admin, I need to set the HTTP Only setting in the Magento admin to 'No'. Before I do this, I am not able to login via Chrome – other browsers do not seem to have this issue for me.

Now I've come across a new (but probably the same) issue while making an extension – I am able to read cookies via Chrome but not set them. There were no issues with using Firefox. To make sure it's not my Chrome, I've performed a fresh install by deleting all user data and profiles but the issue persists. Perhaps I should set the cookies via JS only for this extension.

Nothing out of the norm with the cookie setting code:

$cookie = Mage::getModel('core/cookie');
$cookie->set('cookiename','cookievalue',99999);

Best Answer

Don't develop using localhost as your domain name. I typically use apache to setup a fake custom site at a domain like magento.dev, and then add

127.0.0.1    magento.dev

to my hosts file. Beyond working around the cookie problem, this also lets me have an infinite number of sites running locally.