RE: [PHP] Retrieving Session Variables

From: Date: Wed, 22 May 2002 01:45:03 +0000
Subject: RE: [PHP] Retrieving Session Variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-98674@lists.php.net to get a copy of this message
HTTP_SESSION_VARS has no scope within a function. Make it global first... function currentlogin() { global $HTTP_SESSION_VARS; echo $HTTP_SESSION_VARS['name']; return; } ---John Holmes... > -----Original Message----- > From: Tim Greenleaf [mailto:tim_greenleaf@yahoo.com] > Sent: Tuesday, May 21, 2002 9:38 PM > To: php-general@lists.php.net > Subject: [PHP] Retrieving Session Variables > > I am having a problem getting a session variable in the function > (currentlogin) below. I can process the script and in the else statement > "print ($HTTP_SESSION_VARS['name']);" the session variable is printed but > when the function tries to print the session variable, I get an error > indicating an undefined variable. > > If someone could help me out I would appreaciate it. Is there a good > tutorial on how to set and get session variables. From some of the > snippets > I have read in this news group there appears to be several ways to > accomplish this. > > Thanks > > <?php > if (isset($HTTP_SESSION_VARS['name'])==false){ > writelogin(); > } > else { > //Get logged in name and display message asking user if they would > like to log out > print ($HTTP_SESSION_VARS['name']); > currentlogin(); > } > > > function currentlogin() > { > print ($HTTP_SESSION_VARS['name']); > return; > } > > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#98674) next »