Based on cookie common operation and attribute introduction

Recent projects should be used to store some user information; study it to share

cookie is a small piece of text saved in the browser Information, each cookie size is generally not more than 4KB. The browser will automatically attach this information each time a request is issued to the server.


Document.cookie = ‘username = fengkaicahng’;
   
Note setting cookies can only store one

cookies at a time, and you can set the same time without re-assapling the value but will create a new cookie

read Cookie

VAR AllCookies = Document.cookie; // Read all cookie strings // So we must also do a conversion var cookiesAry = Document

   

Value (Must) A key value is used to specify the value of the cookie

Document.cookie = ‘username = fengkaicahng’;
   
Expires specifies the expiration time of cookies; Date.ToutCstring () in format is used ()

var day = new date (); day.gettime (days.gettime () + (1 * 24 * 60 * 60 * 1000)); // Setting the validity period // if not set; The default time is the current session window closing, the failure Document.cookie = ‘username = “+ day +”;
   
Domain specifies the domain name of the Send cookie

Var day = new date (); day.settime (days.gettime () + (1 * 24 * 60 * 60 * 1000)); // Only under this domain name Only send cookie, // If not set; default is to set the domain name // below when setting cookies will take effect under all subdomains of FENGKAICHANG.COOM = ‘username = fngkaicahng; expires =’ + day + ‘; domain =

 PATH specifies the path of cookie   
VAR days = new Date (); day.settime (DAY.GETTIME () + (1 * 24 * 60 * 60 * 1000)); // Only this path and the path sent to the server will send cookie to directly configure / match this match from the root directory is not absolute. If it is not set; the default is the path // below the request to request the cookie. The following configuration will take effect under all request paths of Fengkaichang.com. // Note that the premise of path’s effectiveness is Domain matches success, otherwise it is daukent.cooKie = ‘username = fengkaicahng; expires =’ + day + ‘; domain = fengkaichang.com; Path = /’

 Secure Specifies that cookie can only send it under the encryption protocol HTTPS To server   
VAR days = new Date (); day.settime (days.gettime () + (1 * 24 * 60 * 60 * 1000)); // The value of this attribute is a Boolean value // If this communication protocol is https then the protocol is automatically opened // If the manual settings are sent to send Document.cookie = ‘username = fengkaicahng; Expires =’ + day + ‘under normal HTTP protocol; Domain = fengkaichang.com; path = /; secure = true ‘
The above-based cookie common operation and attribute introduction are all content of Xiaobian sharing to everyone. I hope to give you a reference, I hope everyone will support Tumi Cloud.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment