Page 1 of 1

Online Shopping Cart Question...

Posted: Wed Jul 20, 2005 9:42 am
by Dale
Which is best to use for an online shopping cart?

1. Sessions
2. Cookies

???

Posted: Wed Jul 20, 2005 10:18 am
by nielsene
It depends.

I would probably say Sessions, 9 times out of 10. However, if you want the shopping cart to persist between browser close and re-opens, you'll need to use cookies in addition.

Posted: Wed Jul 20, 2005 10:21 am
by onion2k
Sessions can degrade to _GET session ids if the user hasn't got the capability to use proper memory sessions. I think that's a good reason to use them.

Oh, and obviously when people say sessions or cookies in an ecommerce context, we invariably mean to store an id that is used to store cart data in a database .. you wouldn't store cart data in the session or the cookie. Just an id.

Posted: Wed Jul 20, 2005 10:25 am
by nielsene
onion2k wrote:Sessions can degrade to _GET session ids if the user hasn't got the capability to use proper memory sessions. I think that's a good reason to use them.
There's no such thing as "proper memory session". There's no magic to sessions, it sends the session ID to the browser in one of two ways: either by cookie or via the get query string (or hidden variables in post, etc).

So its more proper to say "Session can degrade to _GET session ids, if the user can't/doesn't accept cookies."

Posted: Wed Jul 20, 2005 10:31 am
by Dale
nielsene wrote:It depends.

I would probably say Sessions, 9 times out of 10. However, if you want the shopping cart to persist between browser close and re-opens, you'll need to use cookies in addition.
I was thinking of sessions, but what happens if the user accidentally closes the browser after ordering 2871 differnet items ?

Posted: Wed Jul 20, 2005 10:34 am
by onion2k
nielsene wrote:
onion2k wrote:Sessions can degrade to _GET session ids if the user hasn't got the capability to use proper memory sessions. I think that's a good reason to use them.
There's no such thing as "proper memory session". There's no magic to sessions, it sends the session ID to the browser in one of two ways: either by cookie or via the get query string (or hidden variables in post, etc).

So its more proper to say "Session can degrade to _GET session ids, if the user can't/doesn't accept cookies."
In IE you can switch off textfile based cookies and yet retain the ability to use session cookies that are held in memory. PHP sessions will still work if the user has memory cookies switched on. Which is what I meant.

Posted: Wed Jul 20, 2005 10:52 am
by nielsene
Dale wrote:
nielsene wrote:It depends.

I would probably say Sessions, 9 times out of 10. However, if you want the shopping cart to persist between browser close and re-opens, you'll need to use cookies in addition.
I was thinking of sessions, but what happens if the user accidentally closes the browser after ordering 2871 differnet items ?
Then the user would lose their shoping cart. For most on-line shops, users aren't putting more than may 10-30 items in their cart, and most users don't acccidently close their browser while shopping. Therefore your concern isn't too common. Shops are also used to a very high percentage of "abandoned" carts -- ie populated carts that never get checked out (ie browser closed, person leaves the site, etc). Many site encourage this behavvoir by only showing you prices/discounts if you add an item to your cart (*cough* amazon *cough* ("This item's price is too low, please add to your cart to see it"... for a several thousand dollar computer))

For places with bigger shopping carts -- for instance places where you're ordering build-to-order desk/bookshelf, etc systems where you have lots of little components to customize and design, the ability to "save" a shopping cart/configuration is VERY useful. This can be done either via cookies or via the database. e.g. a user can store shopping "trips" into the database and the application can show a list of past trips that the user might want to review/add/delete on next visit.

Posted: Wed Jul 20, 2005 11:00 am
by Dale
I might just use sessions then. Cheers for your feedback on my question :D

Posted: Fri Sep 09, 2005 7:17 am
by raghavan20
how about using database instead of sessions???
when i first developed a shopping cart in ASP I used database table to store product ids and quantity.
I had an problem with the sessions in the university server.
I can create both with no technical difficulty.
but i want to know which is the efficient and most accepted solution in most e-commerce sites.

Posted: Fri Sep 09, 2005 7:47 am
by patrikG
depends what you want to achieve. If you want something like persistent sessions you will have to have some kind of data storage, i.e. database (obviously) or filesystem (more of an academic choice). You would store the session-data in the database using session_set_save_handler.