This article mainly introduces PHP three ways to clear the session, interested in the friend's reference, I hope to help you.
Session Delete Clear is very fastidious if we can clear the specified variable if we are not careful to remove all the sessions, let's take a look at some summary.
The first way:unset ($_session[' xxx ']) deletes a single session,unset ($_session[' xxx ') to unregister a registered SESSION variable.
Its effect is the same as Session_unregister ().
Session_unregister () has been abandoned in PHP5.
PHP official Delete session mode
<?php //Initialize session. Session_Start (); /*** Delete all the session variables: Unset ($_session[xxx]) can also be deleted individually. / $_session = Array (); /*** Delete the Sessin ID. Because the session is COOKIE-based by default, use Setcookie to delete the cookie.***/ if (isset ($_cookie[session_name) that contains the session ID. ()]) { Setcookie (Session_name (), ", Time () -42000, '/'); } Finally, the session is completely destroyed. Session_destroy ();? >
Unset ($_session) This function must not be used, it will destroy the global variable $_session, and there is no viable way to restore it. Users can no longer register $_session variables.
second way:Session_unset () or $_session=array () delete multiple sessions
The Third Way:Session_destroy () ends the current session and empties all resources in the session. The function does not unset (releases) the global variables associated with the current session (GlobalVariables), nor does it delete the client's session cookie. PHP's default session is cookie-based, and if you want to delete a cookie, you must use the Setcookie () function.
Summary:
Session_destroy is to unregister all session variables and end session sessions;
If you want to delete some session data, you can use the unset () function or the Session_destroy () function. The function of the unset () function is to release the specified session variable, which is called in the following format:
<?phpunset ($_session[' Jugelizi ');? >
The purpose of the Session_destroy () function is to delete the session all and call the format as follows:
<? PHP Session_destroy ();?>
Tip: Session_destroy () will reset the session and you will lose all saved session data.
Session_unset () does not unregister the session variable, but empties the value of all session variables.
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP implements the conversion of images to ASCII code
Use of the switch statement in PHP
How to get the first letter of Chinese pinyin in PHP program