perhaps someone could tell me what is going on here...
<?
session_start();
if ($_GET['test']) {
$_SESSION['testvar'] = "testing...";
header("Location: ./test.php");
}
?>
<html>
<head>
<title>test</title>
</head>
<body>
<p><? print_r($_SESSION); ?></p>
<p><a href="<? echo $_SERVER['PHP_SELF']; ?>?test=yes">test link</a></p>
<?
if ($_SESSION['testvar']) {
echo "unsetting...";
unset($_SESSION['testvar']);
}
?>
<p><? print_r($_SESSION); ?></p>
</body>
</html>
the function of the code should be, when the "test link" is followed, the "testvar" in session is set. the page then prints out the contents of the session. if that "testvar" is set, then it is unset and the session is printed again.
so, ideally the output is:
Array ( [testvar] => testing... )
test link
unsetting...
Array ()
instead, it displays:
Array ()
test link
unsetting...
Array ()
this baffles me because, it prints the contents of $_SESSION, which is nothing and then goes suceeds on a test which it has not shown in the session. i know the variable does get set, because if the unset() call is commented out i get:
Array ( [testvar] => testing... )
test link
unsetting...
Array ( [testvar] => testing... )
any ideas? i'm totally stuck.