...

View Full Version : Solution to Cookies



heldl
06-16-2007, 07:50 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="cookies.js"></script>
</head>

<body>
<script>
if(getCookie('username')){
alert("welcome back, " + getCookie('username'))}
else{
var myname = prompt("What's your name?", "");
setCookie('username', myname, 365)
}
</script>
</body>
</html>








Cookies.ks
function setCookie(name, value, expiredates)
{
var exp = new Date ();
exp.setTime(getTIme()+ expiredates);
document.cookie = name+"="+value;expires+"="+exp.toGMTString();
}

function getCookie(name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(name + "=")
if (c_start!=-1)
{
c_start=c_start + name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}

A1ien51
06-17-2007, 05:04 PM
And what is your question or reason for posting this? Helps if you add text and not just code.

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum