unset ($_session) Pendant han unset ($_session[' id ')

Source: Internet
Author: User
$_SESSION['id'] = 1;

The unset($_SESSION); next time you refresh session_start(); the page,

$_SESSION['id']The values are = 1 out again!

And unset($_SESSION['id']); the use can be cleared normally!

Who can tell the details, thank you!

Reply content:

$_SESSION['id'] = 1;

The unset($_SESSION); next time you refresh session_start(); the page,

$_SESSION['id']The values are = 1 out again!

And unset($_SESSION['id']); the use can be cleared normally!

Who can tell the details, thank you!

Because of the fact that "literally" is not always obvious and easy to "actually".

unset($_SESSION['id'])Changes are the $_SESSION values of the image;
unset($_SESSION)Changes are $_SESSION references that do not change the $_SESSION image.

Only changes $_SESSION to the image, just will change the actual Session.

If, however, $_SESSION = []; you can achieve the purpose of emptying the Session.

It is said that the direct value of the $_SESSION variable can also be changed to the $_SESSION image.

So, I guess, the PHP engine $_SESSION modifies the Session by changing the last-referenced image, and if there is no $_SESSION change, skip this step.

In the context of the current request, $_SESSION this variable is actually a reference to the array that stores the session value.

unset($_SESSION)It simply writes this variable in the context of the current request $_SESSION , and does not actually move to an array of values that store the session.

The next time a request is made, the variable in the context of the next request will naturally be directed to the reference of the $_SESSION array that stores the session value.

In fact, Kmxz said very clearly,
Whether it's $_get or $_post,$_cookie or $_session,
They are a variable of PHP itself,
When a request comes in, Zend will parse Query_string,body,http_cookie,phpsessionid,
The values are then loaded into the above variables, where the session is in the file in/tmp and the file name is the Phpsessionid value (which means by default).
Session of the storage file is a certain chance to trigger the deletion, if not deleted,
On the next request, Zend will find the session file according to the value of Phpsessionid, and then read and deserialize (non-PHP unserialize function) after re-loaded into the $_session, so the ID has a value.
And you unset ($_session[' id '), changed the value of the corresponding ID in/tmp (actually deleted), so after re-request, the ID is not.

  • 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.