SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Shopping cart best practices

    I'm building a shopping cart. I would like to keep items in the cart in the database. That means I need to tie the db information to the session. I can either store the session id in the database, or store a cart id in the session. Is one better than the other?

    Most carts tend to keep information for a long time. Should I extend the session expiration length to a day? a week? a month? infinite? Or should I be setting a cookie with an extended expiration date, and using the standard for sessions?

    Are there any other best practices I should know about?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Session IDs are not guaranteed to be globally unique over all time, while your cart IDs are, so storing the cart ID in the session is better than storing the session ID in the cart.

    I'd advise against extending the session expiration time... you have to keep all those sessions around on your server, whereas if you use cookies, the cookie gets stored by the client, not you.

  3. #3
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Session IDs are not guaranteed to be globally unique over all time, while your cart IDs are, so storing the cart ID in the session is better than storing the session ID in the cart.

    I'd advise against extending the session expiration time... you have to keep all those sessions around on your server, whereas if you use cookies, the cookie gets stored by the client, not you.
    Good points. Cookies it is.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •