tracking cookies

Any problem with javascript can be discussed here.
Locked
pryj
Posts: 56
Joined: Tue Dec 21, 2004 1:06 pm

tracking cookies

Post by pryj »

This script uses cookies to display the number of times
a user has visited your page.
Image

Code:

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = ****.cookie.length;
var i = 0;
while (i 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
****.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
****.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = ****.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = ****.cookie.length;
return unescape(****.cookie.substring(offset, endstr));
}


****.write("You've been here " + amt() + " times.")
_________________


Locked