The destruction of session variables in PHP

Source: Internet
Author: User
Tags session id php session

This article is mainly about the destruction of PHP session variables are introduced, need friends can come to the reference, I hope to help you

1. What is session?

Equivalent to a client (can be browser, app, FTP and other, and the same browser open several more than a different client) to a server access, this period the server to create a unique logo (session_id session_name), In fact, an array of arrays (), the beginning and end of the session does not begin with the input username password on the business, nor does it end with closing the browser and refreshing the Web page.

Destruction of 2.session variables

Program code

  

Session_unset ();

Session_destroy ();

?>

Session_unset ()

Releases all $_session variables that are currently created in memory, but does not delete the session file and does not release the corresponding session ID

Session_destroy ()

Deletes the session file for the current user and releases the session ID, and the contents of the $_session variable in memory remain

"Note":

To delete the session method:

1. unset ($_session[' xxx ') deletes a single session,unset ($_session[' xxx ')) to unregister a registered session variable. The effect is the same as Session_unregister (). Session_unregister () is no longer used in PHP5, and can be put into the doghouse.

Unset ($_session) This function must not be used, it will destroy the global variable $_session, and there is no feasible way to restore it. Users can no longer register $_session variables.

2, $_session=array () Delete multiple sessions

3. Session_destroy () ends the current session and empties all resources in the session ... The function does not unset (release) the global variable (globalvariables) associated with the current session, nor does it delete the client's session cookie. PHP default session is based on cookies, and if you want to delete cookies, you must use the Setcookie () function.

Return value: Boolean value.

Function Description: This function ends the current session, this function has no arguments, and the return value is True

Session_unset () The function no longer works if $_session is used. Since PHP5 is bound to use $_session, this function can be shelved.

You can draw a step to delete a session:

①session_start ()

②$_session=array ()/unset ($_session[' xxx ')

③session_destroy ()

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.