|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-05 05:23 UTC] AchimWinkelmann at web dot de
The manual says at topic XCIII. SESSION HANDLING FUNCTIONS under headline EXAMPLES within the NOTE, 'you do not need to use the global keyword for $_SESSION'. In fact you 'may not use the global keyword' when accessing $_SESSION from within a function, otherwise a different global variable seems to be created/accessed (PHP 4.3.0, WinXP)! Maybe it is no bug, but I miss any sematically sense. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Bogus? PAGE 1 (test_index.php): =========================================================== <? include ('test_session.inc'); session_start (); ?> <HTML><HEAD><TITLE>Test session</TITLE></HEAD> <BODY TEXT="#000000" LINK="#FFCC00" ALINK="#33FF00" VLINK="#FFCC00" bgcolor="#FFFFFF"> <br> <u><i>test_index.php</i></u><br> <br> <? sessRESTORE(); $_SESSION['direkt'] = 'Wert'; sessVAR( 'test', '1234' ); print( "<i>session_id() = '".session_id()."'</i><br>\r\n" ); print( "<i>\$_SESSION['test'] = '".((isset($_SESSION['test']))?$_SESSION['test']:'not set')."'</i><br>\r\n" ); print( "<i>\$test = '".((isset($test))?$test:'not set')."'</i><br>\r\n" ); print( "<i>\$_SESSION['direkt'] = '".((isset($_SESSION['direkt']))?$_SESSION['direkt']:'not set')."'</i><br>\r\n" ); print( "<i>\$direkt = '".((isset($direkt))?$direkt:'not set')."'</i><br>\r\n" ); ?> <br> <a href="test_start.php?<?=SID?>"><b>next</b></a><br> </BODY></HTML> ----------------------------------------------------------- PAGE 2 (test_start.php): =========================================================== <? include ('test_session.inc'); session_start (); ?> <html><head><title>Test session</title></HEAD> <BODY TEXT="#000000" LINK="#FFCC00" ALINK="#33FF00" VLINK="#FFCC00" bgcolor="#FFFFFF"> <br> <i><u>test_start.php</u></i><br> <br> <? sessRESTORE(); print( "<i>session_id() = '".session_id()."'</i><br>\r\n" ); print( "<i>\$_SESSION['test'] = '".((isset($_SESSION['test']))?$_SESSION['test']:'not set')."'</i><br>\r\n" ); print( "<i>\$test = '".((isset($test))?$test:'not set')."'</i><br>\r\n" ); print( "<i>\$_SESSION['direkt'] = '".((isset($_SESSION['direkt']))?$_SESSION['direkt']:'not set')."'</i><br>\r\n" ); print( "<i>\$direkt = '".((isset($direkt))?$direkt:'not set')."'</i><br>\r\n" ); ?> <br> <a href="test_index.php?<?=SID?>"><b>back</b></a> </body></html> ----------------------------------------------------------- FUNCTIONS (test_session.inc): =========================================================== <? function sessVAR ($name, $wert) { global $_SESSION; $_SESSION[$name] = $wert; eval('global $'.$name.'; $'.$name.'=$_SESSION[\''.$name.'\'];'); } function sessRESTORE () { global $_SESSION; while ( list ($key, $value) = each ($_SESSION) ) { eval( 'global $'.$key.'; $'.$key.'=$_SESSION[\''.$key.'\'];' ); print( 'sessRESTORE $'.$key."<br>\r\n" ); } } ?> ----------------------------------------------------------- First Test - PAGE 1 displays: ============================= test_index.php session_id() = 'a8422f455c75aec5a3654c2894f7b4f2' $_SESSION['test'] = '1234' $test = '1234' $_SESSION['direkt'] = 'Wert' $direkt = 'not set' next First Test - PAGE 2 displays: ============================= test_start.php session_id() = 'a8422f455c75aec5a3654c2894f7b4f2' $_SESSION['test'] = 'not set' $test = 'not set' $_SESSION['direkt'] = 'not set' $direkt = 'not set' back First Test - continued: ======================= If I goon switching between these two pages, I get the same results for each page as shown above. For the following second test the statements 'global $_SESSION;' within the functions of 'test_session.inc' are deactivated! Second Test - PAGE 1 displays: ============================== test_index.php session_id() = '91f0a63c90e8a567610a3a9ec5195202' $_SESSION['test'] = '1234' $test = '1234' $_SESSION['direkt'] = 'Wert' $direkt = 'not set' next Second Test - PAGE 2 displays: ============================== test_start.php sessRESTORE $direkt sessRESTORE $test session_id() = '91f0a63c90e8a567610a3a9ec5195202' $_SESSION['test'] = '1234' $test = '1234' $_SESSION['direkt'] = 'Wert' $direkt = 'Wert' back Second Test - continued: ======================== If I goon switching between these two pages, I get the correct results as shown in Page 2 Display!