Session-what is the difference between the COOKIE sent by the browser's HTTP request and the COOKIE planted by the PHPsetcookie function?

Source: Internet
Author: User
Tags send cookies
What is the difference between the COOKIE sent by the browser's HTTP request and the COOKIE planted by the PHPsetcookie function? Can the two cookies be viewed in the browser-> webpage information-> website COOKIE display? What is the difference between the COOKIE sent by the browser's HTTP request and the COOKIE planted by the PHP setcookie function? Can the two cookies be viewed in the browser-> webpage information-> website COOKIE display?

Reply content:

What is the difference between the COOKIE sent by the browser's HTTP request and the COOKIE planted by the PHP setcookie function? Can the two cookies be viewed in the browser-> webpage information-> website COOKIE display?

The cookie set by setCookie is written into the browser in the form of an hhtp response header. If the path or domain matches, the HTTP request header is added to the next HTTP request. The two are set in different ways, but once set successfully, they can be seen in the browser Developer Tools.

For more information, see the http://segmentfault.com/q/1010000002655809/a-1020000002655842 of a previous question.

The PHP setcookie function notifies the browser to save the cookie. The COOKIE sent by the HTTP request of the browser sends the previously saved cookie to the server and tells the server that I have the cookie.

In fact, you must first understand the role of a cookie, which is generated by the server and sent to the client for user authentication. In this way, when the client (browser) sends a request to the server, the cookie is also sent to the server so that the server only needs to check whether your cookie is correct, in this way, you do not need to check whether the user's account and password are correct every time. (Of course, cookies have other functions, such as storing users' access habits ).
And for your problem
Client (browser): the cookie sent by the HTTP request is generated by the server and sent to the browser. Each time the browser sends a request to the server, the cookie is carried back.
Server: The setcookie of PHP is actually the process in which the server generates the cookie.
The two are the same thing. So what the browser sees is the same thing.

1. Cookie is a unified standard. The same method should be used for sending. Otherwise, it will lose its meaning.
2. the browser does not send cookies, so there is no "Cookie sent by the browser HTTP request", which is sent from the server to the browser, because http is a stateless protocol, only cookies and sessions are used to identify a user.

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.