No, you don't need a form to do what you want I think. Unless you can't popup an inputbox with PHP to get a name from the user. I don't know PHP. It was just an workflow idea how you could do it in pure javascript, which you can convert to PHP I thought. But you need a function in PHP where you can popup an inputbox for it to work...
Here is the javascript version of it. This time I tested it, and as you can see, not much had to be changed (only had to add [1] and replace "" with null):
code:
<html>
<head>
<title>Main Page</title>
<script language="JavaScript">
function GetName() {
var username = unescape(document.cookie)
username = username.split("=")[1]
if (username == null) {
username = prompt("What is your name?","")
var expiredate = new Date()
expiredate.setMonth(expiredate.getMonth() + 1)
document.cookie = "Name=" + username + ";expires=" + expiredate.toGMTString() + ";path=/"
}
return username
}
function ClearName() {
var expiredate = new Date()
document.cookie = "Name=;expires=" + expiredate.toGMTString() + ";path=/"
}
</script>
</head>
<body onLoad="javascript:alert(GetName() + ', welcome...');">
<input type="button" value="Clear cookie..." onClick="ClearName()">
<br>main page
</body>
</html>
So this is the concept, I guess. I'm sure this can be done in PHP also, but instead of cookies, use a database... BTW, this is only a very crude example.
PS: about the semicolons, you don't need them in javascript. But it is indeed a good habbit to put them there...