I have a complicated script containing a problem with a destroyed session variable (through the $_SESSION array) which reappears on the next page.
Here is a small script with the same behaviour :
=======================
<?php
ob_start() ;
?>
<html>
<body>
<?php
// Useful function
function dumpArray($Tablo)
{
$Entete = date("H:i:s - ") ;
while (list ($Cle, $Valeur) = each ($Tablo))
echo ($Entete . $Arguments[$i] . '[ ' . $Cle . ' ] = ' . $Valeur . "<br/>\n") ;
}
// Beginning of session variables usage
session_start();
dumpArray($_SESSION) ;
if (isset($SESSION['Foo_2']))
unset($SESSION['Foo_2']) ;
else
if (isset($SESSION['Foo_1']))
$SESSION['Foo_2'] = 'blue' ;
$SESSION['Foo_3'] = 'yellow' ;
$SESSION['Foo_1'] = 'red' ;
unset($_SESSION['Foo_3']) ;
?>
<a href="#" onclick="window.location.href='session_test.php';"><b>Next call</b></a>
<br>
</body>
</html>
<?php
dumpArray($_SESSION) ;
// session_write_close() ;
ob_end_flush() ;
// Should be :
// First call : Foo_1 defined
// Second call : Foo_1 and Foo_2 defined
// Next odd call : Foo_1 defined
// Next even call : Foo_1 and Foo_2 defined
//
// Is :
// First call : Foo_1 defined
// Second call : Foo_1 and Foo_2 defined
// Other calls : Foo_1 and Foo_2 defined
//
// session_write_close() ; // doesn't change anything
?>
Just copy this script in a file named 'session_test.php' and lauch it then click on the 'next call' link several times.
(have also attached the script as a zip file)
Should be something obvious I don't see...
Or maybe the ob_xxx functions interfere (but I need them in my true script).
Works same under Windows/IIS and Linux/Apache.
Any idea ?
Thanks.