The server can filter and regularly maintain the information contained in Cookies to determine the status during HTTP transmission. The most typical application of Cookies is to determine whether a registered user has logged on to the website. The user may be prompted to determine whether to keep the user information during the next visit to simplify the logon procedures, these are the functions of Cookies. Another important application scenario is "Shopping Cart. Users may select different items on different pages of the same website within a period of time. These information will be written into Cookies so that information can be extracted during the final payment.
// Create a Cookiefunction createCookie (userName, password) {var date = new Date (); date. setTime (date. getTime () + 60*1000*60*24); // Save the document for one day. cookie = "userName =" + escape (userName) + "; expires =" + date. toUTCString (); // The escape Function encodes the String, and setTime is the current document of the Cookie. cookie = "password =" + escape (password) + "; expires =" + date. toUTCString (); alert (document. cookie);} // obtain the Cookie data function getCookie (value) {var cookieString = document. cookie; var start = cookieString. indexOf (value + "="); // locate the value position. if (start =-1) return null; start + = value. length + 1; // value length + 1, that is, = the position behind var end = cookieString. indexOf (";", start); // The length of valuer + 1 lookup; position if (end =-1) // that is, there is only one Cookie, so no; return cookieString. substring (start); return cookieString. substring (start, end) ;}// Delete Cookiefunction delCookie () {var date = new Date (); var user = getCookie ("userName "); var pwd = getCookie ("password"); date. setTime (date. getTime ()-1); // reduce the current time to 1 ms from the current system time to a negative value, and the Cookie will expire in the system, the document will be destroyed. cookie = "userName =" + escape (user) + ";" + "expires =" + date. toUTCString (); document. cookie = "password =" + escape (pwd) + ";" + "expires =" + date. toUTCString ();}