0

Hello dear friends..
I have some confusion in following code.

<?php
session_start();

$_SESSION["name"]= "abc";

session_destroy();

echo $_SESSION["name"];
?>

as I am assigning value to session variable, after assigning I am destroying whole session but after destroying as I echo $_SESSION["name"] it show value.
It is printing value even session has been destroyed..
Can any one tell me its reason.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by panhwer
0

A quote from the PHP session_destroy manual

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
0

Thanks dear...
bus still I have confusion like on same page it is showing session variable are set.
but as on second page I start session and the write print_r($_SESSION).. the output is array() mean session array have no item.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.