Magento Cookies not Working in Chrome or Opera on Frontend

So, I was testing the “this site is using cookies” functionality in Magento. It worked fine on a local environment but failed to work on a test “live” IP address site. I say failed, but it worked fine in IE and Firefox whereas in Chrome hitting the “I agree to cookies” button didn’t set a cookie and redirected. I eventually solved it.

Having gone through the trials of changing the cookie name to not use underscores, checking server timezones, Magento timezones, php timezones I found an old post somewhere that said Google Chrome was deliberately programmed to ignore cookies on IP “domains”.  This led me to try a few things and I eventually came to this successful conclusion:

In the cookienotice.phtml file (or wherever your cookie notice ends up) change this:

Mage.Cookies.set(‘<?php echo Mage_Core_Helper_Cookie::IS_USER_ALLOWED_SAVE_COOKIE; ?>’, ‘<?php echo Mage::helper(‘core/cookie’)->getAcceptedSaveCookiesWebsiteIds()?>’, new Date(new Date().getTime() + <?php echo Mage::helper(‘core/cookie’)->getCookieRestrictionLifetime() ?> * 1000));

to this:

Mage.Cookies.set(‘<?php echo Mage_Core_Helper_Cookie::IS_USER_ALLOWED_SAVE_COOKIE; ?>’, ‘<?php echo Mage::helper(‘core/cookie’)->getAcceptedSaveCookiesWebsiteIds()?>’, new Date(new Date().getTime() + <?php echo Mage::helper(‘core/cookie’)->getCookieRestrictionLifetime() ?> * 1000),“/”,null);

This will set the path to “/”and the domain to null – and the cookie work fine and dandy.

Note: I felt frustrated as the frontend cookie generated by the site was working and the admin login was also working fine.

 

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *