Summary of the methods for deleting and clearing sessions in php, phpsession. Summary of methods for deleting and clearing sessions in php, phpsessionsession deletion and clearing is very important. if we define it, we can clear the specified variables. Otherwise, we will accidentally clear all sessions and summarize the methods of deleting and clearing sessions in php. phpsession
Session deletion clearing is very important. if we define it, we can clear the specified variables. Otherwise, we will accidentally clear all sessions. let's take a look at some of the summary below.
Method 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 () has been deprecated in PHP5.
Official php session deletion method
<? Php // initialize session. session_start ();/*** delete all session variables .. unset ($ _ SESSION [xxx]) can also be deleted one by one. * ***/$ _ SESSION = array ();/*** delete sessin id. because the session is cookie-based by default, setcookie is used to delete the cookie containing the session id. * **/if (isset ($ _ COOKIE [session_name ()]) {setcookie (session_name (), '', time ()-42000 ,'/');} // Finally, the session is completely destroyed. session_destroy ();?>
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.
Method 2:Session_unset () or $ _ SESSION = array () delete multiple sessions
Method 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;
If you want to delete some session data, you can use the unset () function or session_destroy () function. The unset () function is used to release the specified session variable. The Call format is as follows:
<?phpunset($_SESSION['jugelizi']);?>
Session_destroy () is used to delete all sessions. The Call format is as follows:
<?PHP session_destroy(); ?>
Tip: session_destroy () will reset the session, and you will lose all the saved session data.
Session_unset () does not cancel the session variable, but clears the values of all session variables.
The above content is all described in this article. I hope you can help me.
Deleting and clearing reset sessions is very important. if we define this function, we can clear the specified variables. Otherwise, we will accidentally clear all sessions...