RE: [PHP] More Fun With Sessions!

From: Date: Wed, 23 Jan 2002 21:06:03 +0000
Subject: RE: [PHP] More Fun With Sessions!
Groups: php.general 
Request: Send a blank email to php-general+get-81758@lists.php.net to get a copy of this message
Your code works fine on my FreeBSD box running php 4.0.4pl1 but not one running php 4.0.6 ... May explain your linux issues? i.e. versions of php ... -----Original Message----- From: Richard Baskett [mailto:rick@baskettcase.com] Sent: Wednesday, January 23, 2002 3:37 PM You only need to register the variable once when you initiate the session. Also as of php 4.1 I believe you do not have to register your session vars you can just acccess them like $_SESSION['counter']: http://www.php.net/manual/en/ref.session.php Basically what I see you're doing is reregistering the variable on each page which initializes it as 0 and so when you do $counter++ you're always going to get 1.. > test.php: > <?php > session_start(); > session_register('counter'); > $counter++; > echo("You have visited this page $counter times.\n"); > ?> > <a href="test2.php">click here</a> > > test2.php: > <?php > session_start(); > session_register('counter'); > $counter++; > echo("You have visited this page $counter times.\n"); > ?> > <a href="test.php">click here</a> > > Shouldn't this hold the same counter variable for both pages? It > works fine on my linux box, but on the FreeBSD box, $counter is always > 1. I think that if I could get something like this script working, > then the shopping cart would also work. Sorry for the long message! > Any help would be greatly appreciated. >

« previous php.general (#81758) next »