Current location: Hot Scripts Forums » Programming Languages » PHP » Using Sessions for a shopping cart


Using Sessions for a shopping cart

Reply
  #1 (permalink)  
Old 11-30-05, 10:57 PM
mcrob mcrob is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-01-05, 02:53 AM
Iudex Iudex is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-01-05, 09:59 AM
mcrob mcrob is offline
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-02-05, 10:29 AM
xqus's Avatar
xqus xqus is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 12-02-05, 12:15 PM
mcrob mcrob is offline
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 12-02-05, 12:25 PM
xqus's Avatar
xqus xqus is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 12-02-05, 01:01 PM
mcrob mcrob is offline
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 12-02-05, 02:14 PM
xqus's Avatar
xqus xqus is offline
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:
PHP Code:

$productsRaw=explode("," $cookie);

foreach(
$productsRaw as $productRaw) {
    
$productInfo=explode("="$productRaw);
    echo 
"Product ID:"$productInfo[0]."<br />\n";
    echo 
"Quantity: ".$productInfo[1]."<br />\n";

__________________
- xqus
phpSec - A PHP security library.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 12-03-05, 07:11 PM
mcrob mcrob is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
shopping cart project d2daj Script Requests 2 11-20-05 12:43 AM
pro shopping cart pi3rc3 Script Requests 0 06-09-05 08:36 PM
shopping cart cutomization limits?? vega PHP 1 06-11-04 12:26 PM
OO Shopping Cart Serialization wheezy360 PHP 1 12-29-03 09:09 PM
shopping cart problem darton520 PHP 2 11-03-03 12:20 PM


All times are GMT -5. The time now is 06:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.