$ _ Does the COOKIE variable obtain the cookie value by reading the cookie file?

Source: Internet
Author: User
Tags chrome developer
$ _ Does the COOKIE variable obtain the cookie value by reading the cookie file? Why does the $ _ cookie variable still exist after the COOKIE file is deleted? $ _ Does the COOKIE variable obtain the cookie value by reading the cookie file?
Why does the $ _ cookie variable still exist after the COOKIE file is deleted?

Reply content:

$ _ Does the COOKIE variable obtain the cookie value by reading the cookie file?
Why does the $ _ cookie variable still exist after the COOKIE file is deleted?

The cookie generation process is as follows: after the server sets a cookie, it is returned to the browser. The browser stores the cookie locally on the client. the browser will carry this cookie for every http request sent to the server, if the client deletes a cookie, the cookie in the request sent to the server is empty. You can check the Cookie field in requuest_header of the browser console.

session_start();var_dump($_COOKIE);

The above two lines of code enable the session. Open chrome developer Mode

Then I try to kill the cookie.

New session.A sessionID can be considered as a sessionThere is no relationship between sessions.

And$_COOKIEThis is a system variable. Can be Baidu PHP system variables. Several times, what is each variable, what is the division of labor and responsibilities, this can be explored.

It is in the header of the user request. It is included in each request,

Strictly speaking, it is not by reading files.

When sending a request, the browser will include the cookie in the Request Header:

Then the server parses the Cookie header and saves it to the $ _ COOKIE variable.

However, you do not know how to delete the cookie file. Because the cookie file is deleted, the cookie is cleared. In this case, when the browser sends a request immediately, $ _ COOKIE should be empty.

The front-end can set the cookie value. When an http request is sent, the cookie value is sent to the server.
The server reads the http request header information, record or perform data verification, or sets a new cookie.
After receiving the response from the HTTP request, the client will return the cookie value through 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 a request. It depends on whether the front-end has set a cookie for this request.
If it is set, the request will still be sent to the server, and the server will still be able to receive the request ~~~

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.