The destruction of the session variable in PHP

  • 2021-01-19 22:03:56
  • OfStack

1. What is session?
Equivalent to a client (can be a browser, app, ftp other, and with a browser to open several and even different client) a visit to the server, the server during this build 1 only 1 label (session_id session_name), actually is also a array Array (), the beginning and the end of Session enter the user name password is not in our business, also not to close the browser and the web page refresh

2. Destruction of session variables
The program code
< ?php
session_unset();
session_destroy();
? >

session_unset()
Release all $_SESSION variables that have been created in memory, but do not delete the session file and do not release the corresponding session id

session_destroy()
Delete session file corresponding to current user and release session id, the contents of $_SESSION variable in memory remain

[Note] :

Delete session method:

$_SESSION['xxx'] $_SESSION['xxx'] $_SESSION['xxx'] $_SESSION['xxx'] $_SESSION['xxx'] $_SESSION['xxx'] $_SESSION['xxx'] It has the same effect as session_unregister(). session_unregister() is no longer in use in ES61en5 and can be put out of favor.

unset($_SESSION) This letter is not available. It destroys the global variable $_SESSION, and there is no practical way to restore it. Users can no longer register for the $_session variable.

$_SESSION=array(); $_SESSION=array()

3, session_destroy() Ends the current session and empties all resources in the session. The default session is based on cookie. To delete cookie, you must use the setcookie() function. The default session is based on cookie.

Return value: Boolean value.

This function terminates the current session. This function takes no arguments and returns the value true

session_unset() This function no longer works if $_session is used. Since PHP5 must use $_session, this function is out of favor.

The following steps can be taken to remove session:

1) session_start ()

(2) $_SESSION = array ()/unset ($_session [' xxx '])

(3) session_destroy ()


Related articles: