Cookie is the property of document. Some websites store data on the user's local terminal (a string on the user's hard disk) to identify the user's identity ). Defined in rfc2019.
Cookie is initially designed for the server program, so the server script can read and write the cookie value of the client. There are two methods to write a cookie: writing a cookie on the server side and writing a cookie on the client side.
At this time, we can access the value on both the server and client.
Cookie attributes: expires, path, and secure.
Expires: specifies the cookie survival period.
By default, cookies exist temporarily and their stored values only exist during browser sessions. After exiting the browser, these values disappear.
If the existence of a cookie exceeds the session period, you need to set expires as a future date. The browser will save the cookie to a local file. Once the end date is exceeded, the browser
Automatically delete the cookie from the cookie file. (the cookie folders of different browsers are different ).
By default, the cookie is associated with the webpage that is created, the webpage in the same directory as the webpage, and the webpage in the subdirectory of the webpage.
Secure: specifies how to transmit cookies. It is transmitted only when http (insecure) or https tutorial or other secure protocol connections are used.
Cookie storage and access:
Document. cookie = 'version = '+ encodeuricomponent (saved value );
The cookie value cannot contain semicolons, commas, or blank spaces. Therefore, encodeuricomponent is usually used. Do not forget decodeuricomponent () decoding when you read it;
It is a list of name = value. Separated by semicolons. You can use string. indexof (), string. substring (), or string. split () to split the characters into separate cookies.