Welcome to... |
|||||
MyersDaily |
Copy and paste the entire page below to use these cookie functions. |
function makeCookie(Name,Value,Expiry,Path,Domain,Secure) { //Bunch of arguments if (Expiry != null) { //if you want to save the cookie var datenow = new Date(); //get a date datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry)); //mutiply the number to make it represent days Expiry = datenow.toGMTString(); //convert to GMT time } //ends that. And now... Expiry = (Expiry != null) ? '; expires='+Expiry : ''; //has an expiration? Path = (Path != null)?'; path='+Path:''; //has a path? Domain = (Domain != null) ? '; domain='+Domain : ''; //has a domain? Secure = (Secure != null) ? '; secure' : ''; //Secure? document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure; //Make the cookie! } function readCookie(Name) { //Your name goes here! :-) var cookies = document.cookie; //Copy your cookies if (cookies.indexOf(Name + '=') == -1) return null; //Woops, no cookie! var start = cookies.indexOf(Name + '=') + (Name.length + 1); //Jump to start of cookie var finish = cookies.substring(start,cookies.length); //Get a count from the cookies finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';'); //Find end of cookie return unescape(cookies.substring(start,finish)); //Here's your cookie! ( Sorry, no chocolate chips. :-) } /* Syntax rules: *********************** Making the Cookie / Reading the Cookie *********************** A. Name 1. No characters besides A-Z, a-z, numerals, and the underscore. 2. Probably don't want to use an especially long name. B. Value 1. Here's the actual content. 2. Anything goes here up to 4000 characters. C. Expiry (This is what shines!) 1. Type in the NUMBER OF DAYS to save the cookie or: 2. Leave this out and the cookie will expire during the current session. D. Path 1. Sets a restriction on the portion of the server allowed to access a cookie. 2. Use a slash "/" to allow any page from your site to obtain the cookie. E. Domain 1. Sets a domain as in MAIL.yahoo.com ( EMPHASIS ADDED!!! ). 2. By default this would be set to the same as the cookie's origin domain. F. Secure 1. If you want access to the cookie ONLY during a secure connection. 2. Normally you'd want this to protect sensitive information. You would type this... makeCookie('friendly_cookie','Mr. Smith is tall.',18,'/'); ...to make a cookie with a NAME of friendly_cookie, a VALUE of "Mr. Smith is tall.", an EXPIRATION of 18 days later, and having the most accessible PATH of /. You would type this... var YOUR_VARIABLE_NAME = readCookie('friendly_cookie'); ...to set the variable of YOUR_VARIABLE_NAME to the value of the cookie with a NAME of friendly_cookie or to null if there was no cookie available named friendly_cookie. Smile! :-) This code is free for the taking. Consider it to be in the public domain. Feel free to contact me at e_mayilme@hotmail.com or visit my website which has even more cool scripts at https://www.angelfire.com/yt/jmyers. Note: You'll probably want to remove most comments from this script as is to shorten download times. */ //These cookie functions written 1999-2000 by Joseph K. Myers |