Cookies
The cookie is nothing more than a text file assigned to
unique visitors to your site. Cookies are also referred to as Magic Cookies, Persistent
Cookies, and Tokens. They are saved in the browser's directory or folder and read while
browsing. Most of the information in a cookie isn't used for much, but you can take
advantage of them and use them for something useful. The most-often use of Cookies are for
personalization preferences like Planet
Direct, and online ordering like WWF
ShopZone (heh) and Paintballstore.com.
Misinformed people may tell you Cookies are dangerous when
in reality they are safe. Cookies cannot take a "snap-shot" of your hard drive,
Cookies cannot be accessed by any site outside the site that issued the Cookie, and most
importantly Cookies cannot automatically nab your E-Mail address (unless you type it into
a form). Some people think Cookies are an invasion of privacy because sites are writing
information to their hard drives without them knowing it. To get an idea of how often
Cookies are issued to you, turn them on. In IE 4, go to View > Internet Options >
Advanced. About half-way down, under Cookies, click on Prompt before accepting Cookies and
hit OK. After some surfing you'll be surprised to find out how often they're used. To view
the Cookies on your hard drive (Windows95/NT), look in your Windows\Cookies subdirectory.

Here's an example of a Cookie using Javascript:
Here's how this is done:
1. Add the following Javascript just before your
</HEAD> Tag:
<script>
cookie_name = "Counter_Cookie";
function doCookie() {
if(document.cookie) {
index = document.cookie.indexOf(cookie_name);
} else {
index = -1;
}
if (index == -1) {
document.cookie=cookie_name+"=1; expires=Tuesday, 01-Apr-1999 08:00:00 GMT";
} else {
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
count = eval(document.cookie.substring(countbegin, countend)) + 1;
document.cookie=cookie_name+"="+count+"; expires=Tuesday, 01-Apr-1999
08:00:00 GMT";
}
}
function gettimes() {
if(document.cookie) {
index = document.cookie.indexOf(cookie_name);
if (index != -1) {
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
count = document.cookie.substring(countbegin, countend);
if (count == 1) {
return (count+" time");
} else {
return (count+" times");
}
}
}
return ("0 times");
}
</script>
2. Add onUnload="doCookie()" to your <BODY> Tag:
<BODY
onUnload="doCookie()">
3. Add this wherever you want the cookie to be seen:
<script>
document.write("<p align=center><font face=Verdana size=3>This is the
number of times you have visited this page: "+gettimes()+"<br>Reload and
watch the counter go up</font></p>");
</script>
You'll recognize the HTML between the
<SCRIPT> </SCRIPT>
Tags, modify it as needed.

|