View Full Version : Using cookies in a shopping cart

08-23-2006, 11:47 AM
I am about to develop a shopping cart system, however i am wondering what is the advantage of using cookies over sessions. In the past I have generally tried to avoid using cookies some ppl turn them off and I dont like cookies. I always turn off any auto complete or remember this options on my browsers. I understand generally developers use cookies for a shopping cart systems however i was wondering weather i could pass the cart information through php's super duper session vars. Of course I know this could work but what will be the disadvantages and generally why do developers use cookies :confused:

08-23-2006, 01:43 PM
Well, sessions use cookies too in most cases, so not much of a difference there. You could save the cartinfo to the database linking it to a specific session, but it would only save data in the cookie, not the cookie itsself.

08-23-2006, 05:11 PM
Thanks, I will have to use cookies then. I will make it a something that users need in order to use the shoping cart feature. I can easily test by setting the cookie and testing to see if it was set. If not an "Please enable cookies" error message. If I were to use sessions then i presume I would need to ensure that the session ID stayed the same. I think I will just use standard cookies and just store a cart ID to refrence a file on the server that stores there information. I am trying to save the client some money by not introducing a whole mmbers section. Anyway all I need is an paypal system so I may find something ready made for this, that will handle all this. :thumbsup:

08-23-2006, 05:57 PM
Just in case you're not aware of this, you cannot set a cookie in PHP and then immediately test to see if that cookie got set. The page has to cycle back to the browser before the cookie actually gets set. You could use Javascript's cookie functions to test this, however. Of course, you'll also need to test to see if Javascript is enabled. :)

I'd actually recommend sessions, just for their ease of use. Sessions (for the most part) take care of their ID for you; you don't really have to think about it.

08-24-2006, 06:16 AM
I am building a shopping cart and I am using sessions because of their ease of use and no one can shut them off via their browser.

08-31-2006, 11:00 AM
I am building a shopping cart and I am using sessions because of their ease of use and no one can shut them off via their browser.

Sessions can be shut of in the same way cookies are, right ? Opening a session creates a session cookie on the client. Or am I missing something ?