Home>

Session deletion and emptying are very particular about if we define it, we can clear the specified variables, otherwise all sessions will be cleared by accident.Let's look at some conclusions.

The first way:unset ($_ session ["xxx"]) deletes a single session. unset ($_ session ["xxx"]) is used to unregister a registered session variable.

Its effect is the same as session_unregister ().

session_unregister () is deprecated in php5.

PHP official delete session

<?php
     //Initialize the session.
     session_start ();
     /*** Delete all session variables .. You can also use unset ($_ session [xxx]) to delete them one by one.
**** /
     $_session=array ();
     /*** Delete the sessin id. Since session is cookie-based by default, use setcookie to delete the cookie containing the session id.
     if (isset ($_ cookie [session_name ()])) {
        setcookie (session_name (), "", time ()-42000, "/");
     }
     //Finally destroy the session completely.
     session_destroy ();
?>
</pre>
</div>
<p>
unset ($_ session) This function must not be used.
It destroys the global variable $_session, and there is no feasible way to restore it.
Users can no longer register $_session variables.
</p>
<p>
<strong>
The second way:
</strong>session_unset () or $_session=array () delete multiple sessions
</p>
<p>
<strong>
The third way:
</strong>session_destroy () ends the current session,And clear all resources in the session.
This function does not unset (release) global variables related to the current session, nor does it delete the client's session cookie. The default session of PHP is cookie-based. If i want to delete a cookie, you must use the setcookie () function.
</p>
<p>
summary:
</p>
<p>
session_destroy is to cancel all session variables and end the session;
</p>
<p>
If i want to delete some session data, you can use the unset () function or the session_destroy () function. The function of unset () is to release the specified session variable. The calling format is as follows:
</p>
<div>
<pre>
<?php
unset ($_ session ["jugelizi"]);
?>

The role of the session_destroy () function is to delete all sessions.The calling format is 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 session variables, but clears all session variable values.

php
  • Previous 3 things PHP programmers should not ignore
  • Next JavaScript child window calls parent window variables and functions