Can cookies replace session variables?

Results 1 to 5 of 5

Thread: Can cookies replace session variables?

  1. #1
    Jochem Guest

    Default Can cookies replace session variables?

    posted this yesterday, but i got no reply....maybe better luck this time:<BR><BR>I have developed a shopping-cart system which remembers the contents of someone&#039s shopping cart by using a array stored in a session variable.<BR><BR>I have a few questions about this:<BR><BR>Is it bad to use sessions in this case? the arrays can get kinda big(like 20 products, each having a name, description, price etc..) would this cause a problem with like 30 simultaneous users ?<BR><BR>I&#039m thinking about switching to cookies instead of the sessions, but would a 2 dimensional array be difficult to store in a cookie(or multiple cookies). Especially when it has 5 columns and 30 rows or so. Or would this be no problem ?<BR><BR>anyway, the bottom line....will my app perform better if i would use cookies to store cart-content in ?...assuming this is possble of course...<BR><BR>any help appreciated,<BR>Jochem

  2. #2
    Richard A. Lowe Guest

    Default Here we go again..

    There was just a bit of a discussion recently on this topic on the Advanced board, but I&#039ll chime in here.<BR><BR>Is it bad to use sessions? Well, although I avoid them generally, I don&#039t have anything against them. Microsoft says:<BR><BR>"ASP automatically creates a Session for every user that hits a Web server. Each Session has about 10 KB of memory overhead (on top of whatever data is stored in the Session)"<BR><BR>So that&#039s still 1 MB or less of session data for your scenario (which I estimated a lot of values for so it&#039s not accurate, by any measure). Which doesn&#039t seem like a lot really. And assuming generously of 1KB per product, do you really want 20KB of data going back and forth between your server and the browser when your visitor&#039s connection could still be &#060;shudder&#062; 28.8Kbps?<BR><BR>If you were certain you wouldn&#039t be growing over 30 - 50 simultaneous shopping carts of 20 items or less for some time to come, the convenience of session variables is hard to beat.<BR><BR>If you&#039re going to grow beyond that, then sessions or cookies storing an identifier that pointed to a shopping cart stored in a database would be an option.<BR><BR>But not cart-content in cookies.<BR><BR>Richard

  3. #3
    Join Date
    Dec 1969
    Los Angeles, CA

    Default No we dont

    He SEEMS to be using then very incorrectly. You DO NOT save the array in the session or cookie but you save each item in the DB. Where did the array come in <BR><BR>For each user you save the item he MAY want to purchase in the DB and continue the same way. If later he decide not to buy it delete from the DB<BR><BR>This is the way to do it

  4. #4
    Richard A. Lowe Guest

    Default You'll have to take that up with Bill...

    I actually like the idea for a smaller site (of arrays in Session for a shopping cart, that is). <BR><BR>I didn&#039t occur to me, though, till Bill put up this FAQ:<BR><BR><BR>Richard

  5. #5
    Join Date
    Dec 1969

    Default Yep, yep, yep, yep...

    &#062; I actually like the idea for a smaller site (of arrays in <BR>&#062; Session for a shopping cart, that is). <BR><BR>Me, too. Why not? The coding is dirt simple. And it&#039s not *that* hard to later convert to a DB solution if you really need to. If you&#039re just trying to get something up and running on a tight budget and tight schedule and the "numbers" (memory usage) work out... Again, why not?<BR><BR>Sorry, Akhilesh, but I disagree with you on this one.<BR><BR><BR>

Posting Permissions

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