Notes on cookie

Today the project mentioned test, had no bug, to sort out what the cookie knowledge, in 58 projects account, cookie use is not much, but notes due to related content and http data exchange, or to learn about it

HTTP protocol is defined using a mechanism to record information about the client and server interaction, this mechanism is called cookie, cookie specification defines the format of the server and client interaction information, lifetime, range, safety.

Cookie stored in the remote browser and thus the data identifying the user track and mechanism. From the realization say, Cookie is a small piece of data stored on the client browser (ie client) Cookie interaction via HTTP protocol and server-side.

Cooke is independent of the language exist, strictly speaking, Cookie is not implemented by PHP, Java and other languages, but rather indirectly operated by Cookie these languages, it sends an HTTP command, the browser will receive instruction and return to the server operating Cookie . Therefore, Cookie is implemented and managed by the browser.

Cookie is part of the HTTP header, i.e., sending or requesting Cookie now, is the data field; the setcookie () function and the like must be called before the data, and this header () function is the same. But you can also use output buffering function delays script, set all know Cookie and other HTTP headers.

Cookie information stored in the cookie itself contains attributes and user-defined attributes, a cookie can contain only one custom key / value pairs. Cookie itself attributes "Comment", "Domain", "Max-Age", "Path", "Secure", "Version".

Comment property is the description of the cookie generated the cookie;

 

Domain attribute definition can access the cookie domain name, for some large sites, if you want the cookie can be shared in a subsite, you can use this property. For example, setting Domain to .bigsite.com, the sub1.bigsite.com and sub2.bigsite.com can access saved in the client's cookie, then also need to Path is set to /.

 

Effective time Max-Age attribute defines the cookie, with a second counter, when expired, the cookie information from the client is not attached to the HTTP message header is sent to the server.

 

Can access the cookie path Path attribute defines the site pages, Path is generated cookie path, this time may be the cookie path, and which sub-page access in default path; Path can be set / the cookie all pages can be accessed at the site.

 

Secure security attribute values ​​define the cookie, when the value must be true before the cookie from the client in an HTTP message in the attached state HTTPS sent to the server, when the HTTP cookie is not transmitted; to be false when the Secure transfer cookie, Secure HTTP by default in the state is false.

 

Version attribute defines the version of the cookie, the cookie is defined by the creator.

 

There are cookie domain and path of this concept. Domain is the domain of the concept, because the browser is an attention to safety environment, so between different domains can not access each other's cookie (of course, can be reached by cross-domain cookie access to special settings). Path is the routing of the concept, cookie created a web page can only be accessed was all pages in the same directory or subdirectories with this page, web access can not be obtained in other directories

 

Cookie size is generally limited to 4K, but, as the different browsers, Cookie are not the same size

Published 41 original articles · won praise 8 · views 20000 +

Guess you like

Origin blog.csdn.net/huma8848888/article/details/102671544