Discussion Locked

Write a cookie and the points are yours

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need a javascript cookie script that will write a cookie with the contents of a form and then when the user tries to login the script would compare the user name and the username on the cookie. There is no password. Also it will login the user andkeep a log of which links he has clicked and then make those links unavailable. The script should also keep track of how many links the user has clicked and read it each time he logs in and when the number reaches 200 should show a alert message. The number of links the user has clicked should be in a variable so that they can be shown on a page.

7 replies

by jeremy

I would do that using session variables. I would use VBScript - create a
database, and populate it with variables such as username, links, etc. Use
event handlers (ie when a user clicks on a link, have an 'onClick' event to
write to the db). Then, when the user logs in, you can immediately compare
his username (assuming you are using Windows NT) with that in the database,
and immediately access all the other info. You can then use the variables in
the database to control what the user sees.

by mightyduk

put the javascript in a file called challenge.js in the same directory:
function login(){
checkCookie();
if(document.login_form.user.value!=user){
alert("Login Failed!");
return;}

for(var i=0;i=200){
alert("Congratulations you hit 200!");}
}

function checkCookie(){
if(document.cookie){
eval(document.cookie);
var linklist=links.split(",");
for(var i=1;i

by mightyduk

and finally:

function linkto(target){
if(linksbyname[target.href]){
document.login_form.user.select();
document.login_form.user.focus();
return false;
}
else {
linksbyname[target.href]=true;
target.id="done";
numlinks++; document.login_form.numlinks.value=numlinks;
links+=","+target.href;
document.cookie="links='"+links+"'"+expiry;
document.cookie="numlinks="+numlinks+expiry
return true;
}
}

var numlinks=0;
var links="";
var expiry=";expires=Fri, 31-Dec-2099 12:00:00 GMT";
var user="";
var linksbyname=new Array();

the cookie will expire at the end of the century, should be long enough? It runs with IE5, you might have to play with it a little for Netscape. Email me if you have questions

This discussion is closed to new replies.