Cookies are always stored on the client side and are divided into: memory cookies and hard disk cookies by location.
1. memory cookies are maintained by the browser, stored in memory, and disappear after the browser is closed, for short periods of time.
2. The hard disk cookie is saved on the hard drive and has an expiration time, unless the user manually cleans it up or expires, otherwise the cookie will not be deleted. exist for a long time.
In time, cookies can be divided into: non-persistent cookies and persistent cookies
Properties of the Cookie:
Domain: field that represents the domain or subdomain that the current cookie belongs to
For Set-cookie returned by the server, if domain is not specified, the value of domain is the primary domain name of the request that defaults to the currently committed HTTP.
Path:cookie Path
Expire time/max-age: Indicates the expiration date of the cookie.
If the cookie returned by the server does not specify its expire time, then the current expiration date of the cookie on the surface is the current session. This cookie is deleted when the page is closed.
Secure: can only be transmitted with HTTPS. For transmitting cookies that contain authentication information
HttpOnly: Indicates that this cookie must be used for HTTP or HTTPS transmissions.
Limitations of Cookies:
(1) The cookie is appended to each HTTP request, so the traffic is virtually increased.
(2) Security is a problem because the cookie in the HTTP request is passed in plaintext. (except with HTTPS)
(3) The size of the cookie is limited to around 4KB. is not enough for complex storage requirements.
Basic use of Cookies (PHP):
Set cookie variable: Setcookie (first name, value)
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7A/A5/wKioL1auxrbhhS-3AAAX8PP6b18741.png "title=" Picture 1.png "alt=" Wkiol1auxrbhhs-3aaax8pp6b18741.png "/>
Take COOKIE variable: $_cookie[' name ']
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7A/A5/wKioL1auxxfgZJm5AAAJCCw3Ht8463.png "title=" Qq20160201104500.png "alt=" Wkiol1auxxfgzjm5aaajccw3ht8463.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7A/A5/wKioL1auySbTfvdgAAC5xFZ3euk059.png "title=" QQ picture 20160201104903.png "alt=" Wkiol1auysbtfvdgaac5xfz3euk059.png "/>
Advanced use of Cookies:
1.cookie data can only be string data
2.setcookie, can be done to increase the deletion, does not exist then increases, the existence is modified! Delete to set the value to NULL
Failure period of 3.cookie variable
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7A/A6/wKiom1auyobB0ewgAAAWCHeyb1w163.png "title=" Picture 2.png "alt=" Wkiom1auyobb0ewgaaawcheyb1w163.png "/>
4.cookie exists the concept of valid paths,
5.cookie is a strictly differentiated domain name.
6.Set-cookie: Sent from the server side to the client, that is, the corresponding Set-cookie
When the server is first sent to the client through Set-cookie , the client does not accept the cookiebecause the client does not request the server again, and Set-cookie is through Response sent to the client, the cookiecan only be obtained once the request is requested again.
This article is from the "Joxiong" blog, make sure to keep this source http://joxiong.blog.51cto.com/9068286/1740339
PHP----HTTP protocol Cookie