After much hair pulling I have found something very strange about how PHP handles the superglobal $_SESSION when register_globals is ON. consider this code:
<?
session_start ();
function upper ($array)
{
foreach ($array as $key => $value)
{
$array[$key] = strtoupper ($value);
}
}
?>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="submit" name="submit" value="before">
<input type="submit" name="submit" value="after">
</form>
<?
if (isset ($_POST['submit']) && $_POST['submit'] == 'before')
{
$_SESSION['test'] = 'this is a test';
print_r ($_SESSION);
}
if (isset ($_POST['submit']) && $_POST['submit'] == 'after')
{
upper ($_SESSION);
print_r ($_SESSION);
}
?>
Notice that the function "upper" does not return anything. In theory the changes made to variables inside "upper" would have no effect on the varibales outside the function (since it is a local variable scope). Strangley though, when the above script is run with register_globals ON the $SESSION array is affected by the "upper" function and when register_globals is OFF the "upper" function does not effect $SESSION. Is this by design? Is there any workaround for this in a register_globals ON environment?