Does the $_cookie variable get the value of a cookie by reading a cookie file?

Source: Internet
Author: User
Tags chrome developer
Does the $_cookie variable get the value of a cookie by reading a cookie file?
Why does the value of the $_cookie variable exist after the cookie file is deleted?

Reply content:

Does the $_cookie variable get the value of a cookie by reading a cookie file?
Why does the value of the $_cookie variable exist after the cookie file is deleted?

The process of creating a cookie is this: after the server sets the cookie, it returns to the browser, and the browser stores the cookie locally on the client, and every time the browser requests an HTTP request to the server, the cookie will be taken, and if the client deletes the cookie, The cookie in the request sent to the server is empty, and you can observe the cookie field in the Requuest_header of the browser console

session_start();var_dump($_COOKIE);

The above two lines of code open the session. Open Chrome Developer mode

So I tried to kill the cookie.

A new session. There's 一个sessionID 可以认为是一个会话 no connection between sessions.

And $_COOKIE This is a system variable. Can Baidu PHP system variables. Several, each variable is what, what division of labor and responsibility, this can go to explore under.

is the header of the user request, each request will be taken,

Strictly speaking not by reading the file.

When the browser sends the request, it will include the cookie in the request:

The server side then parses the cookie header and coexists to the $_cookie variable.

But I don't know what your so-called Delete cookie file is exactly. Since the cookie file was deleted, the equivalent of the cookie being emptied, the $_cookie should be empty when the browser immediately sends the request.

The front end can set the cookie value, and when sending an HTTP request, the cookie value is sent to the server side
The server is logging or validating data by reading the header information of the HTTP request, or setting a new cookie
After receiving the reply from the HTTP request, the client will bring the cookie value back to the Set-cookie
The browser then saves the cookie to the local cookie file ~ ~ ~

Deleting a local cookie file does not mean that there is no cookie information when sending the request, depending on whether the front end is setting a cookie for this request
If it is set up, the request will still be sent to the server, the server can still receive ~ ~ ~

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