Unset ($ _ SESSION) does not imply unset ($ _ SESSION ['id'])

Source: Internet
Author: User
{Code ...} the value 1 of $ _ SESSION [& #039; id & #039;] is retrieved after unset ($ _ SESSION) is used; session_start () is refreshed next time! The unset ($ _ SESSION [& #039; id & #039;]) can be cleared normally! Who can tell me in detail? Thank you!
$_SESSION['id'] = 1;

Usedunset($_SESSION);Next time you refresh the pagesession_start();After,

$_SESSION['id']Value= 1Retrieved again!

Useunset($_SESSION['id']);Then it can be cleared normally!

Who can tell me in detail? Thank you!

Reply content:
$_SESSION['id'] = 1;

Usedunset($_SESSION);Next time you refresh the pagesession_start();After,

$_SESSION['id']Value= 1Retrieved again!

Useunset($_SESSION['id']);Then it can be cleared normally!

Who can tell me in detail? Thank you!

As a result, "literally" is not always easy to adapt to "actually 」.

unset($_SESSION['id'])Changed$_SESSIONObject value;
unset($_SESSION)Changed$_SESSIONHas not changed.$_SESSIONObject.

Only change$_SESSIONFor example, the response changes the actual response Session.

However, if$_SESSION = [];To clear the Session.

This indicates that the value is directly equal$_SESSIONChanges$_SESSIONObject.

So, I guess the PHP engine will$_SESSIONModifies the Session of the most referenced object. If no$_SESSIONChanges.

In the context of the current request,$_SESSIONThis variable is actually a reference to the array storing session values.

unset($_SESSION)Only$_SESSIONThis variable is empty and does not actually move to an array that stores the session value.

In the next request$_SESSIONThe variable points to the reference of the array that stores the session value.

In fact, kmxz makes it clear that,
Whether it is $ _ GET or $ _ POST, $ _ COOKIE or $ _ SESSION,
They are a variable in php,
When a request comes, zend will parse query_string, body, HTTP_COOKIE, phpsessionid,
Then load the value into the above variables, where the session exists in the file in/tmp, and the file name is the phpsessionid value (both refer to the default value ).
The session storage file may trigger deletion if it is not deleted,
In the next request, zend finds the session file based on the value of phpsessionid, reads and deserializes the SESSION file (non-php unserialize function), and reloads it into $ _ session, so the id has another value.
After you unset ($ _ SESSION ['id']), the corresponding id value (actually deleted) in/tmp is changed. Therefore, after a new request, no.

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.