Using Sessions for a shopping cart

11-30-05, 10:57 PM
|
|
Coding Addict
|
|
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Using Sessions for a shopping cart
Hey there whats up I got a question. I was browsing shopping cart websites like Rocafella and babyphat for example and when you add a product to a shopping cart and when you close down all your browsers and when you go back to those websites those products are still stored in your shopping cart because cookies are being used. My question is, is there a problem with using sessions when a customer is purchasing products but then decides to close the browser?
And if using sessions is a great way, whats the best solution to delete the incomplete shopping cart. So when a user decides to leave the website and not come back, is there a simple code to do so by the session id?
Last edited by mcrob; 11-30-05 at 11:30 PM.
|

12-01-05, 02:53 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm only coding ASP, so I'm probably not the right person to answer. But doesn't Sesson removes themselves when you close the browser? But yet, you can use sessions. Still I would use cookies, and make the cookie erase itself after X days.
|

12-01-05, 09:59 AM
|
|
Coding Addict
|
|
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yeah....
Its because my main concern is this. When a user adds a product to the shopping cart then they add another product to the shopping cart so they have a total of 2 products in the shopping cart, how can I store the X amount of products that the user stored in a cookie?
|

12-02-05, 10:29 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Location: Bergen, Norway
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
By default the session cookie is destoyed when the user closes the browser. But you can modify the session cookie to last longer, and that way keep the session even if the user closes his browser.
Anyway, if you want to store the cart in a cookie, you could make a list of all the products id's seperated by a comma, and then retrive that cookie, explode() it and you should be able to figure out what products the user has in his cart.
__________________
- xqus
phpSec - A PHP security library.
|

12-02-05, 12:15 PM
|
|
Coding Addict
|
|
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You know whats funny. thats so true! I can do that. My question is what if they make more than 1 quantity per item?
|

12-02-05, 12:25 PM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Location: Bergen, Norway
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by mcrob
You know whats funny. thats so true! I can do that. My question is what if they make more than 1 quantity per item?
|
productid=quantity,productid2=quantity2
Just a suggestion 
__________________
- xqus
phpSec - A PHP security library.
|

12-02-05, 01:01 PM
|
|
Coding Addict
|
|
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Im a lil confused
productid1=1, Quantity=1, productid2=2 Quantity=2
|

12-02-05, 02:14 PM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Location: Bergen, Norway
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by mcrob
Im a lil confused
productid1=1, Quantity=1, productid2=2 Quantity=2
|
I was thinking more like
productid1=quantity1,productid2=quantity2,producti d3=quantity3
Then you could do:
__________________
- xqus
phpSec - A PHP security library.
|

12-03-05, 07:11 PM
|
|
Coding Addict
|
|
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I read through this website and it gave me a good feel on how to make a shopping cart with cookies and sessions.
http://www.macromedia.com/devnet/dre.../php_cart.html
My only problem that I have now is what if the user decides not to come back to your website? What I wanted to do was first generate a random session id, when the user adds a product to there shopping cart, then store there random generated session id to a cookie then store it into there computer. Then store the products and the quantity into the database. So then whenever they want to come back then there products are just sitting there and they can close there browsers, turn off there computer for the day. Come back and there products are already in the shopping cart. My problem that Im having is what if the user decides not to come back? How can I make it so if they dont come back in one month, not only will the cookie be deleted but it will delete there products that was added the cart from the database.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|