This article introduces the differences between session_unset and session_destroy functions and some different methods for deleting variables. This article introduces the differences between session_unset and session_destroy functions and some different methods for deleting variables.
Script ec (2); script
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.
| The Code is as follows: |
|
Session_start ();
Session_unset ();
Session_destroy ();
Session_write_close ();
Setcookie (session_name (), '', 0 ,'/');
Session_regenerate_id (true );
?>
|
Session_destroy ()
Delete the session file corresponding to the current user and release the session id. The $ _ SESSION variable in the memory is retained.
Therefore, to release all resources of a user's session, execute the following code in sequence:
| The Code is as follows: |
|
|
$ _ SESSION ['user'] = 'user1 ′;
Session_unset ();
Session_destroy ();
?> |
Method for deleting a session:
1. unset ($ _ SESSION ['xxx']) deletes a single session. unset ($ _ SESSION ['xxx']) is used to unregister a registered session variable. It works the same as session_unregister. Session_unregister () is no longer used in PHP5 and can be used in the Cold palace.
Unset ($ _ SESSION) is not available. It destroys the global variable $ _ SESSION and there is no feasible way to restore it. You can no longer register the $ _ session variable.
2. $ _ SESSION = array () delete multiple sessions
3. session_destroy () ends the current session and clears all resources in the session .. This function does not unset (release) The global variables related to the current session, nor delete the client session cookie. the default session of PHP is cookie-based. to delete a cookie, you must use the setcookie () function.
Summary:
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.