NYCPHP Meetup

NYPHP.org

[nycphp-talk] preventing randomized session variable from changing when page is refreshed

Kristina Anderson ka at kacomputerconsulting.com
Wed Aug 20 18:58:10 EDT 2008


Yes, but if I do $_SESSION['cart_id'], it is effectively the same 
thing, I'm using this random string as an identifier for the unique 
cart.  This is effectively the same as $_SESSION['session_id'] -- only 
the name is different.

the unique identifier is generated when index.php loads, and is passed 
as a querystring throughout the user's shopping and each product they 
view/order is tagged with their unique identifier.

The problem is that if they refresh/reload index.php...that value will 
change and their cart will be nuked.  Which will be bad.  

One thing that I just thought of a couple minutes ago would be to just 
use index.php to generate that...then include a new page and exit 
index.php so they won't ever be going back to that page during the 
session.

As for why I do things the way I do...I am using $_SESSION and not just 
$_GET which may not have been clear from what I posted.


> On Wed, Aug 20, 2008 at 5:38 PM, Kristina Anderson
> <ka at kacomputerconsulting.com> wrote:
> > John -- store the cart items in the $_SESSION array and only write 
to
> > the database when they check out?
> 
> Or store the cart in the database, and just store a key in the session
> such as $_SESSION['cart_id']
> 
> > I am using PHP session but this variable is being passed in, as a
> > unique identifier for that session/cart.
> 
> As a GET variable?  Why would you do this?  Cookies/sessions were
> invented to making shopping carts work.
> 
> Your code to generate a session_id is pointless... ditch the
> session_id code and just call session_start() on every page.  What do
> you think is wrong with the default session_id generation?
> 
> -John C.
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
> 




More information about the talk mailing list