Online Shopping Cart Question...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Online Shopping Cart Question...

Post by Dale »

Which is best to use for an online shopping cart?

1. Sessions
2. Cookies

???
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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."
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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 ?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

I might just use sessions then. Cheers for your feedback on my question :D
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
Post Reply