Shopping Cart Empties Abruptly – Cookies Not Persisting

cartcheckout

I upgraded from 1.8 to 1.9.1.

Add to cart goes to an 'empty cart'.

I ensured var (cache, session, session logs appear) was writable, refreshed cache and session (then same thing happens), cookie lifetime set to 86400, I tried cookie path '/' and cookie domain (various configs of mydomain.com, .mydomain.com). When I change these last cookie configs, I can add to cart and get to the onepage checkout, but on the billing information step it redirects back to an empty cart.

All settings in system->web->session validation settings set to no except Use SID on Frontend.

Also tried using db session storage instead of files.

When I enter date on the server it shows the correct BST time.

The cart page is http, the checkout https. All good when I run

n98-magerun.phar sys:check

What could be the problem?

Update

So after it went well again last night I have the same problem. I had just cloned the site and created a test environment, changed core_config_data, repointed app/etc/local.xml, flushed the cache and reindexed, and the site looks the same. I notice that before, when I could add to cart, there was the extra cookies in the console (PHPSESSID, BX, cfduid) but they're not there now. Also the frontend cookie changes between before the add to cart and after the add to cart. Now both sites show an empty cart after add to cart.

Best Answer

I have faced the similar issue once on Magento 1.5 and fixed it by increasing the cookie life time to 86400 under

Sytem -> Configuration -> Web -> Session and Cookie Management


The Reason that I found out after doing some research on internet and different forum is that in Magento, by default cookie lifetime is set to 3600 (1 hour). But if the end users computer time runs ahead of server’s time, cookies will not get set for Magento frontend as well as backend. For example, end user’s computer time is 1 hour forward than server’s time, that means the cookie (holding user’s session id) will expire as soon as user logs in or tries to add an item.