Page 1 of 1

session variables

Posted: Thu Feb 28, 2008 11:01 pm
by paqman
This is probably a really dumb question but I can't find the answer anywhere else. When I create a session variable ($_SESSION["name"]) is it possible to use a variable for its name ($_SESSION[$name])? The session variable is called frequently and having it predefined at the top of the file would make changes quite easy. Thanks!

Re: session variables

Posted: Fri Feb 29, 2008 12:25 am
by Peter Anselmo
Using a variable as an index for the session array is perfectly valid.

Code: Select all

 
$_SESSION['bar'] = "Hello World";
$foo = 'bar'
echo $_SESSION[$foo] //prints "Hello World"