Re: $_SESSION issues

From: Date: Fri, 09 May 2003 04:19:46 +0000
Subject: Re: $_SESSION issues
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146966@lists.php.net to get a copy of this message
Actually page1.php $_SESSION['GLOBALS']; should be: foreach($GLOBALS as $var => $val) { $_SESSION[$var] = $val; } "Shawn McKenzie" <nospam@mckenzies.net> wrote in message news:20030509041530.58839.qmail@pb1.pair.com... > I need some clarification here please. Maybe not the greatest thing to do, > but I'm just testing and this shows contradictory results in the piece that > doesn't work.. > > This works: > > page1.php > session_start(); > $test = "Test stuff"; > $_SESSION['GLOBALS']; > > page2.php > session_start(); > $var = "test"; > $$var = $_SESSION[$var]; > echo $test; //outputs: Test stuff > > This doesn't work: > > page2.php > session_start(); > foreach($_SESSION as $var => $val) { > $$var = $val; > echo $var; //output: many keys but NEVER test > } > echo $test; //gives Notice: Undefined variable: test > print_r($_SESSION); //outputs: many keys including [test] => 'Test stuff' > > if(array_key_exists("test", $_SESSION)) { > echo "TEST FOUND"; //outputs: TEST FOUND > } > > What gives? TIA > -Shawn > >

« previous php.general (#146966) next »