Destruction of session variables in PHP _ PHP Tutorial

Source: Internet
Author: User
Destroy session variables in PHP. 1. what is session? It is equivalent to an access to the server from a client (which can be a browser, app, ftp, and other clients, and several more clients can be opened in the same browser, 1. what is session?
It is equivalent to an access to the server from a client (which can be a browser, app, ftp, and other clients, and several more clients can be opened in the same browser, during this period, the server creates a unique identifier (session_id session_name), which is actually an Array (). the start and end of the Session do not start with the user name and password entered in the service, it does not end with closing the browser or refreshing the webpage.

2. destroy session variables
Program code
Session_unset ();
Session_destroy ();
?>

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.

Session_destroy ()
Delete the session file corresponding to the current user and release the session id. The $ _ SESSION variable in the memory is retained.

Note ]:

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.

Return value: Boolean value.

Function description: This function ends the current session. this function has no parameters and returns true.

Session_unset () if $ _ session is used, this function no longer works. Since PHP 5 must use $ _ session, this function can be used in the cold room.

The steps for deleting a session are as follows:

① Session_start ()

② $ _ SESSION = array ()/unset ($ _ session ['XXX'])

③ Session_destroy ()

Why? It is equivalent to an access to the server from a client (which can be a browser, app, ftp, etc., and a few more open clients in the same browser ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.