Whilst looking at yours I've run into a similar problem and perhaps we'll both get help however I've found that if you make sure and destroy an existing session what I sent you does work but even after using unregister and destroy the variable is still holding on.
Here is the entry page
<?php
if(isset($kill)) {
$name = NULL; // empty the variable
session_unregister("name"); // unregister it
session_destroy(); // kill the session
header("location: test.php"); // reload the page
}
session_start(); // start session
echo "Variable is: <b>".$name."</b><br>";
//$name = "Test";
session_register('name');
$_SESSION['name'] = "Test";
?> <a href="test1.php">Continue the session</a>
Here is the page to verify the variable:
<?php
session_start();
if(isset($name)){
echo 'Hello <b>'.$name."</b><br>";
echo "<a href='destroy.php'>Destroy</a><br>";
echo "<a href='test.php'>Back to home</a><br>";
}
else {
echo "The name did not carry over";
}
?>
Here is to destroy the variable If you are killing a session, and then checking for its existance later on in the same script, the session will still exist. you need to reload or redirect before the session becomes unregisted. Which is why there is a "kill" variable in the first script:
<?php
$_SESSION['name'] = NULL;
session_unregister('name');
session_destroy();
if(!session_is_registered('name')){
echo "You are now logged out!<br>";
echo "At this point name variable = ".$name."<br>";
echo "<a href='test.php?kill=y'>Login</a><br />";
}
?>
I think clearing the variable is probably harder than anything. This problem with the sessions not clearning even when you've told it to is probably why you were unable to get this to work the first time. I've tried everything and have been unable to clear the variable. So if at first you dont succeed. REFRESH! and or close the browser window 😉
You can see this working here:
http://www.jldb.org/test.php