Jump to content

session_destroy(): not working?


Recommended Posts

I wonder why session_destroy() does not work on the page (destroy_session.php).


Set the session:


<?phpsession_start();$_SESSION['username'] = "username1";$_SESSION['password'] = "password1";$_SESSION['array'] = array('array0','array1','array2');?><html><head><script type="text/javascript">var sPageFullPath = String(window.location.href);var iDelim = sPageFullPath.lastIndexOf("/");var sPageRootPath = sPageFullPath.substring(0,iDelim+1);var iCount = 3;var iTimerCount = iCount*1000;var sRedirectURL = "get_sessions.php";window.onload = CountdownTimer;function CountdownTimer(){	if (iCount>0)	{		document.getElementById("CountdownTimer").innerHTML = "This page will redirect in "+iCount+" seconds to " + sRedirectURL;		iCount--;		setTimeout("CountdownTimer()",iTimerCount);	}	else	{		window.location = sPageRootPath + sRedirectURL;	}}</script></head><body><p>This page assigns values to SESSION valuables.</p><p id="CountdownTimer"></p></body></html>

Get the session:


<?phpsession_start();echo "This page shows values to SESSION valuables."."<br />";echo "The username is ".$_SESSION['username'];echo "<br />";echo "The password is ".$_SESSION['password'];echo "<br />";echo "The array is ".$_SESSION['array'][2];echo "<br />";foreach ($_SESSION['array'] as $value){	echo $value;	echo "<br />";}echo "<hr />";print_r ($_SESSION);echo "<hr />";?><html><head></head><body><a href="destroy_sessions.php" title="This page will destroy the session valuables.">destory sessions</a></body></html>

Destroy the session:


<?phpsession_start();echo "This page desttoys the session.";echo "<br />";session_destroy();echo "Those sessions set will not be shown now.";echo "<br />";echo "The username is ".$_SESSION['username'];echo "<br />";echo "The password is ".$_SESSION['password'];echo "<br />";echo "The array is ".$_SESSION['array'][2];echo "<br />";foreach ($_SESSION['array'] as $value){	echo $value;	echo "<br />";}echo "<hr />";print_r ($_SESSION);?>

On the above PHP page, the session valuables are still shown properly.

Edited by Tin
Link to comment
Share on other sites

As explained here, you must clear out the $_SESSION variable also.

// ...session_unset(); // added this linesession_destroy();// ...

Yes. Checked online and added the session_unset() function.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...