Classic cookie functions in action

Try clicking the browser's 'reload' button a few times - you'll see the time of your last visit changing. Then click the 'Remove Cookie' button and reload the page - you'll be asked for your name again.

This version of the page has to use separate cookies for the username and date, storing their values in regular JavaScript variables.

Here's the source for the cookie-handling section of this page:

<BODY BGCOLOR=#FFFFFF>

<h1>Classic cookie functions in action</h1>
<script>
var pcp169Name = getCookie("pcp169Name")
var pcp169Last = getCookie("pcp169Last")
if (pcp169Name != null) {
   document.write('<p>Hi there '+pcp169Name+', you last visited us on '+ pcp169Last+'</p>')
} else {
   pcp169Name = prompt("Please type your name here: ")
   document.write('Welcome, '+ pcp169Name+'!')
}
vdate = new Date()
pcp169Last = vdate.toGMTString()
setCookie("pcp169Name", pcp169Name, 365)
setCookie("pcp169Last", pcp169Last, 365)
</script>