What is Cookie
Cookie
Sometimes use the plural form Cookies
Cookie
That is, by the server to the client's specific information, but this information in a text file stored on the client, and then each time the client sends a request to the server will bring these special information. Server received Cookie
later will verify Cookie
the information in order to identify the user's identity.
Cookie
It can be understood as a temporary pass.
What is the use Cookie
Since our HTTP protocol is stateless, so we have to realize the function of keeping state like landing on the site, then you need the help Cookie
.
Each HTTP request after the data exchange is completed it will close the connection, so the next time an HTTP request can not let the server know your relationship with your last request. The use of Cookie
after your request after the first landing like successful, the server will be in Response
the header information back to your Cookie
information, the next time you visit Cookie time to bring this information, the server will be able to identify you as the a successful user login.
Cookie Content
Cookie
The general format is saved json format, by a number of attributes.
-
name:
Cookie
The name -
value:
Cookie
the value of -
domain: You can use this
Cookie
domain -
path: You can use this
Cookie
page path -
expires / Max-Age: This
Cookie
timeout -
secure: it can only be provided by transmitting the entry https
Cookie
domain properties
The domain generally divided into top-level domain, two domain names, three domain names, and so on.
For example baidu.com is a top-level domain, and www.baidu.com and map.baidu.com is the second-level domain, and so on.
In our Cookie
terms, there is a domain
property that limits what you can use this one when domain names Cookie
. Because each site will basically distribute Cookie
, so the domain
property can make when we visit will not bring Baidu Sina distributed to us Cookie
.
In the same domain name system, the top-level domain is unable to use its secondary domain name Cookie
, that access is not the time to bring baidu.com map.baidu.com distribution Cookie
, and between the two domain names Cookie
also not be shared. But when the two domain names that can be used to access top-level domains Cookie
are.
path attribute
path attribute can access the page path to this cookie. For example, domain is abc.com, path is / test, then only pages under / test paths can read this cookie.
expires / Max-Age attribute
Field set for this cookie timeout. If a value of a set time, then when this time is reached, this cookie failure. If not set the default value of Session, which means failure with the cookie and session. When the browser is closed (not the browser tab, but the entire browser), the failure of this cookie.
Cookie reptiles application
-
In any way, such as browser, selenium, packets, etc., to obtain the corresponding
Cookie
-
The
Cookie
save can be saved to memory, files, database -
I want to use in the
Cookie
project, from the preservation of places outCookie
perform application
PS
我们所说的使用Cookie
进行实现登陆,都是需要服务端支持的,也就是说服务器给我们的Cookie
有一个时间段的生命周期,这样我们保存下来的cookie才能在下次继续使用。