Fw: [PHP] Problems with sessions

From: Date: Tue, 13 May 2003 21:35:57 +0000
Subject: Fw: [PHP] Problems with sessions
Groups: php.general 
Request: Send a blank email to php-general+get-147500@lists.php.net to get a copy of this message
----- Original Message ----- From: "Tomás Liendo" <tomasjliendo@hotmail.com> To: <php-general@lists.php.net> Sent: Tuesday, May 13, 2003 1:47 PM Subject: [PHP] Problems with sessions > Hi people, I need your help: > > I don't understand sessions very well. I'm programming a typical login > system. The user input his user name and password, and I check this > information in a MySQL database. If the user and password exists, I do the > following: > > session_start(); > session_register("authenticated"); > $authenticated="yes"; > > Then, the user has a menu (made with Flash) and can go to diferents pages > (each page is a diferent php file). In each one of those pages I check that > the user is authenticated: > > if($authenticated!="yes") > { > echo "Login error"; > } > else > { > ... > > But $authenticated never has the value yes. I suppose that this is because > the $authenticated doesn't conserve the value between pages, but this the > characteristic of a session variable. Or not? > > Ahead of time, thank you very much, > > Tom. Tom the session_register() function is intended to register a number of SET variables. What you're actually doing is registering a variable that doesn't exist until after it's been registered. To fix simply swap lines and set your varaible before you register it in the session.. session_start(); $auth = "yes" session_register("auth"); However I recommend anyone working with sessions to use the $_SESSION super global array rather than the session functions. It's more direct and alot more intuitive since you're not creating two instances of the variable.. session_start(); $_SESSION['auth'] = "yes"; HTH, Kevin

« previous php.general (#147500) next »