Cookie notes

Source: Internet
Author: User

Cookie introduction


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 origin


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;


Cookie reading:

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.


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.