PHP Shopping cart without login - cookies vs sessions vs both?

jreed121 picture jreed121 · Sep 15, 2011 · Viewed 7.5k times · Source

It's a php based web store without user logins because all of the payments are handled via paypal. My question is what would you guys suggest for the shopping cart - cookies, sessions, or both? I'm not too concerned with the longevity of the shopping cart's contents be I'd like for the user to be able to click around and do a few things before they commit the order. I'm leaning towards sessions because some people may still disable cookies on their machines.

Answer

drew010 picture drew010 · Sep 15, 2011

PHP sessions use a cookie with the session id to track the user. I would go with sessions since it will handle all of the identification for you and make things easier and more transparent.

It is also possible to use sessions with no cookies and it will pass the session id around in the URL. That in some cases can be a security risk, but perhaps not so much in your situation.