For Netscape users, there is a file in the c:\netscape directory called cookies.txt.
Explorer uses a directory to store this data, in c:\winnnt\cookies or c:\windows\cookies.
Many web pages use this file to store information to store session variables,
or to determine if a user is new to a web site.
The file is handled similar to the way an INI file is accessed,
except that cookie data has an "expiration date".
All operations to the cookies file are not written to the hard disk until the
browser is closed. This is transparent to any functions that use the cookies file.
Each element in the file has a keyword, expiration date, and value. To
set a value in the file, a very specific format is needed. Getting a value from this
file involves parsing out each line until the desired element is found.
A set of functions is available for accessing the cookies file.
f_setcookie(keyword,value,exp_date)
Sets a value in the cookies file for the lable specified. Null can be
used in place of the expiration date if the access is session-specific.
Example: f_setcookie("username","jake",null);
f_getcookie(keyword)
Returns the value from the cookies file for the value specified.
Example: cur_name = f_getcookie("username");
Here is the source code for the functions:
function f_getcookieval(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function f_getcookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return f_getcookieval (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function f_setcookie (name, value, expires) {
document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}