This document provides an overview of cookies and sessions. It defines cookies as small text files stored on a user's computer that contain information about a website visit. Sessions are a combination of a server-side cookie containing a unique session token and client-side cookie. The document discusses setting, retrieving, and deleting cookies using JavaScript, as well as the advantages of storing session data on the server rather than in client-side cookies.
8. Setting a cookie Property Description Example name = value This sets both the cookie's name and its value. username=matt expires= date This optional value sets the date that the cookie will expire on. The date should be in the format returned by the toGMTString() or toUTCString() methods of the Date object. If the expires value is not given, the cookie will be destroyed the moment the browser is closed. expires= 13/06/2003 00:00:00 path= path The path gives you the chance to specify a directory where the cookie is active. So if you want the cookie to be only sent to pages in the directory cgi-bin, set the path to /cgi-bin. Usually the path is set to /, which means the cookie is valid throughout the entire domain. path=/tutorials/
9. Setting a cookie Property Description Example domain= domain This optional value specifies a domain within which the cookie applies. Only websites in this domain will be able to retrieve the cookie. Usually this is left blank, meaning that only the domain that set the cookie can retrieve it. Please note that the purpose of the domain is to allow cookies to cross sub-domains. Domain=elated.com if we set domain = www.elated.com cookie will not be read by search.elated.com We cannot set the cookie domain to a domain we’re not in, we cannot make the domain www.microsoft.com . Only elated.com is allowed, in this case.
10. Setting a cookie Property Description Example secure This optional flag indicates that the browser should use SSL when sending the cookie to the server. This flag is rarely used. secure
This function expects the cookie data to be passed to it as arguments; it then builds the appropriate cookie string and sets the cookie.
The function uses a regular expression to find the cookie name and value we're interested in, then returns the value portion of the match, passing it through the unescape() function to convert any escaped characters back to normal. (If it doesn't find the cookie, it returns a null value.)