This is what i have so far, it's called Attempt3.html, I would use PHP, but i don't know how to, i have looked it up, but i can't find anything that does what i want (check for cookie; if no cookie ask for email address; if there is a cookie, welcome user; tell user how many times they have visited)
<html>
<head><script LANGUAGE="JAVASCRIPT"">
<!--//
/ ####################### start set cookie ####################### /
function setCookie(name, value) {
var thisCookie = name + "=" + escape(value) ;
document.cookie = thisCookie;
}
/ ####################### start show cookie ####################### /
function showCookie(){
alert(unescape(document.cookie));
}
/ ####################### start get cookie value ####################### /
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
/ ####################### end get cookie value ####################### /
}
/ ####################### start get cookie (name) ####################### /
function 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 getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
/ ####################### end get cookie (name) ####################### /
/ ####################### start delete cookie ####################### /
function DeleteCookie (name) {
if (GetCookie(name)) {
document.cookie = name ;
}
}
/ ####################### end of delete cookie ####################### /
function NewNamer(){
var now= new Date();
now.setTime(now.getTime() + 365 24 60 60 1000);
var name = GetCookie("name");
if ((!name)||(name=='null'))
{
name = prompt("Please enter your email address:", "");
}
setCookie("name", name);
if (name)
{
document.write("Hello, "+name+"");
setCookie("name", name);
}
else
document.write("Welcome to the page, (No name given) "+
"<a href=\"attempt3.html\" onClick=\"ChangeName();history.go(-1)\">Click here </a>");
}
function ChangeName(){
var name = GetCookie("name");
name = prompt("Please enter your name:","");
setCookie("name", name);
var visits='';
setCookie("counter", visits);
NewNamer()}
/ ####################### count visits ####################### /
function VisitCounter(){
var visits = GetCookie("counter");
if (!visits) { visits = 1;
document.write(", this is your first time here.");
}
else {
visits = parseInt(visits) + 1; document.write(", you have been here " + visits + " times.");}
setCookie("counter", visits);
}
/ ####################### end of count visits ####################### /
//-->
</script>
<!-- ####################### ####################### -->
<script LANGUAGE="JAVASCRIPT">
<!--//
function setcookie(){
document.cookie = 'Cookie Name='+document.form1.cookieName.value;
}
function showCookie(){
alert(document.cookie);
}
//-->
</script>
</head>
<!-- ####################### ####################### -->
<body>
<p><script language="JavaScript">
<!--//
NewNamer()
VisitCounter()
//-->
</script></p>
<!-- ####################### Show cookie button ####################### -->
<form name="form1" form method='Post' Action='welcome1.php'>
<input type="button" value="Show cookie" name="B2" onClick="showCookie()"></p>
<input type="submit" value="Continue" name="tophp" action='welcome1.php'>
</form>
<!-- ##################### End of show button cookie ##################### -->
<script language="JavaScript">
var name = GetCookie("name");
document.write("If you are not "+name+
", then <a href=\"attempt3.html\" onClick=\"ChangeName();history.go(-1)\">click here.</a> ");
</script>
</body>
</html>