Thanks guys, that makes sense...
Wasn't entirely sure if sessions were the way to go or not...

one question Cricket, if the token is in a long lived cookie, why write just
the token to the session? isn't checking both a little redundant? that is
the token itself, not the rest of the data stored in the session...



On Mon, Apr 18, 2011 at 5:51 AM, cricket <[email protected]> wrote:

> On Sun, Apr 17, 2011 at 2:03 AM, Greg Skerman <[email protected]> wrote:
> > Ok so I want to do something which I would imagine should be fairly
> straight
> > forward with sessions, but can't for the life of me find documentation to
> > support it.
> >
> > Basically I want to be able to store the cake Session token in a cookie,
> > then wake the session matching that cookie back up on a subsequent visit.
> >
> > Imagine the following scenario (not precisely what I'm doing, but a good
> > illustration none the less).
> >
> > User visits an online store, and puts a bunch of items in their shopping
> > cart.
> > User then decides to leave the store, without going through the checkout
> > Weeks later, the user revisits the store
> >
> > I want to be able to grab the shopping basket that the user had already
> > filled (stored in the session when the visited), and wake the session
> back
> > up so they don't have to go and fill their basket back up with stuff
> again.
> >
> > I get that I have to somehow store the session token in a cookie, but how
> do
> > i wake expired sessions back up so that the state matches what it was
> when
> > they left the store in the first place?
>
> It's not the session that you want to revive, exactly. A session is
> simply some way to save state between page views. In your example that
> includes the items that have been added to the cart but that's not the
> entirety of the session. In any case, all you want is to get the list
> of items chosen. A shopping cart can be as simple as serializing the
> item IDs in the session cookie or more complicated, like storing them
> in a carts table. Or even the complete item record in a separate
> cart_items table, one row for each item. The latter has the benefit
> that you need only fetch the records from cart_items, rather then get
> the IDs, then make another find on the items table. Probably it would
> be fine to just serialize the IDs in the carts table, though.
>
> So you create a SHA1 token (CHAR(40) for your carts table) for each
> cart and save that to the session, eg.
> $this->Session->write('Cart.token', '...'). But you also write it to a
> separate, long-lived cookie (called, eg. CartToken). Each time a user
> visits the site, if they have an empty session you look for the
> CartToken cookie. If it exists, find the cart record using the token.
> If that exists, write the token to the session again.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to