Storing shopping cart items: cookies, sessions?

I’m currently using only cookies to store the shopping cart items. A few days ago I tried to use the checkout on my site with a foreign computer and I found out I can’t, cause it was disabling cookies.

I know, I know, i’m an idiot. I can’t start to think about how many sales I must of lost because of this. I’m currently programming a new version of my site, in a development area. So I’m going to fix a few bugs and release the new version together.

How to fix?
Anyways, what would be the best way to fix this. I could use sessions, which would work great, but I want users to be able to see their carts after coming back to the site. And what would only be possible with cookies.

So I should probably do something that would check if the user has cookies enabled [try to set test cookie]. And if it can read it then use cookies, if not, use sessions.

Anybody know a better way to do this?


  • Tomer

I have never seen a shopping cart script that does not use cookies or session and I discovered that u cannot always rely on them to get the job done esp with so many mobiles trying to acess sites these days.
Set up a db, generate a code snippet to uniquely id each user store those details and rely on them.
A little bit off the wall but it works

Most every cart uses cookies these days and infact it’s considered a best practice to leave them for 30-90 days with the cart remaining valid for that period. Some sites will attempt to set a temporary cookie (which very few users block) as well. A few, and I do stress few, carts rely url based sessions these days but it is certainly an option and something you could certainly adopt for users not using cookies.

The bottom line is that while many people clear cookies, not many block first party cookies and those that do have a poor internet experience these days. Using single session cookies or sessions in addition to a longer term cookie may be a good idea but if someone has disabled them alltogther good luck to them.

Your analytics should be able to guess just how many people don’t accept them… chances are it’s less than one half of one percent.