This section describes the functions of session_unset () and session_destroy.
Session_unset ()
Releases all the $ _ SESSION variables that have been created in the memory, but does not delete the session file or release the corresponding session
Id
Session_destroy ()
Delete the session file corresponding to the current user and release the session
Id. The $ _ SESSION variable in the memory is retained.
If (session_destroy ())
{
ShowMsg ("logout successful! ", '/Member/login ');
Exit ();
}
Else
{
Unset ($ _ SESSION );
ShowMsg ("logout successful! ", '/Member/login ');
Exit ();
}
Therefore, to release all resources of a user's session, execute the following code in sequence:
Program code
<? Php Tutorial
$ _ SESSION ['user'] =
'Lowell ';
Session_unset ();
Session_destroy ();
?>
Analysis by another user
Session_unregister is used to cancel a session variable;
Session_destroy is used to cancel all session variables and end session;
Session_unset () does not cancel the session variable, but clears the values of all session variables.
In general, you can do this when performing the exit operation:
Session_start ();
Session_unset ();
Session_destroy ();
Header ("location: XXX. php ");
There are many different ways to destroy variables in php. For example: unset (); session_unset (); session_destroy (); but as a special variable, different destruction methods will produce different results.
When unset () is used in php3, a boolean value is returned. However, in php4 and later versions, it is only a statement with no return value. If a global variable of unset () in the function or a value passed by reference, the variable can only be destroyed locally, but the variable in the call environment will keep calling unset () the same value before. If a static variable is unset, the static variable and all its references will be destroyed. If you want to unset a globals variable, you can use the GLOBALS array to destroy it: unset ($ GLOBALS ['str']);
Unset ($ _ SESSION ['str']) deletes a single $ _ SESSION ['str'] variable. If unset ($ _ SESSION) is used, all SESSION files on the server are deleted.
Session_unset () deletes all current session values. The result is the same as session_destroy ();