Jump to content
tinfanide

session_destroy(): not working?

Recommended Posts

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

 

Set the session:

http://learntolive.x10.mx/PHP/Sessions/set_sessions.php

<?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:

http://learntolive.x10.mx/PHP/Sessions/get_sessions.php

<?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:

http://learntolive.x10.mx/PHP/Sessions/destroy_sessions.php

<?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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...