COOKIE: it refers to the data stored on the user's local terminal. It is also related to a specific web page or site. Cookie data is automatically transmitted between the web browser and the Web server. That is to say, when an HTTP request is sent, all cookie values saved under the domain name of the request are sent to the web server, therefore, server scripts can read and write Cookies stored on the client.
Cookie validity period: by default, the cookie validity period is short. Once the user closes the browser, the data stored in the cookie will be lost. To extend the cookie validity period, you can set the max-age value of the cache-control attribute in the HTTP header information or modify the value of the expires attribute in the HTTP header information.
Cookie scope: it is determined by the document source and document path. This scope is configurable through the path and domain attributes of the cookie. By default, cookies are related to the web page on which they are created and visible to the page and other pages in the same directory or subdirectory as the page. Sometimes, you may want the entire website to be able to use the cookie value, no matter which page it is created. To meet this requirement, you can set the Cookie Path (set the path attribute of the cookie. For example, if callback ). By default, the cookie scope is restricted by the document source. However, some large websites want to share cookies between subdomains (for example, servers with www.csh.com domain names want to read the cookie values set under mmm.csh.com domain names, this requires setting the domain attribute of the cookie ).
Cookie quantity and size limit: each Web Server (Domain Name) cannot store more than 50 cookies, and each cookie cannot store more than 4 kb of data. If it exceeds 4 kb, the server cannot handle the issue.
// Add a new cookiefunction addcookie (objname, objvalue, objhours) {var STR = objname + "=" + escape (objvalue); // when the value is 0, no expiration time is set, if (objhours> 0) {var date = new date (); var MS = objhours * 3600*1000; date. settime (date. gettime () + MS); STR + = "; expires =" + date. tostring ();} document. cookie = STR ;};
// Obtain the value of the cookie with the specified name function getcookie (objname) {var arrstr = document. cookie. split (";"); For (VAR I = 0; I <arrstr. length; I ++) {var temp = arrstr [I]. split ("="); If (temp [0] = objname) return Unescape (temp [1]) ;}};
// To delete a cookie with the specified name, you can set its expiration time to a previous time function delcookie (name) {var date = new date (); date. settime (date. gettime ()-10000); document. cookie = Name + "= A; expires =" + date. tostring ();};