Click to See Complete Forum and Search --> : Error Generating Cookies


leong61
07-14-2003, 11:19 PM
The purpose of generating this cookies is for a login form to accept a user id and password and greets the user upon successful login using cookies.

My codes are as follows but cannot work. What should I do?:-


Login Form.html :-

<html>
<meta name="author" content="LYK">
<link rel=stylesheet href="stylesheet.css" type="text/css">
<head>
<title>Login Form</title>

<script language="Javascript" type="text/javascript">

alert("You have reached a Members-Only Site");

function Get_Cookie(name)
{
var start = document.cookie.indexOf(name+"=");
var len = start+name.length+1;
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure)
{
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}

function myfunction()
{
if (login.userid.value=="")
{
alert("Please enter your userid");
login.userid.focus();
login.userid.select();
return false;
}
if (login.password.value=="")
{
alert("Please enter your password");
login.password.focus();
login.password.select();
return false;
}
}
</script>
</head>

<body>
<marquee><h1><font color="#A01080">Welcome to Login Page!!!!!</h1></font></marquee>

<form name="login" method="post" onSubmit="return myfunction()" action="">
<table align="center">
<tr><td><font><b>UserID</b></td><td><input type="text" name="userid" size="20" maxlength="50" value=""></td></tr>
<tr><td><font><b>Password</b></td><td><input type="password" name="password" size="20" maxlength="50"></td></tr>
</table>

<table align="center">
<tr><td><input type="submit" value="Login">
<input type="submit" value="Reset"></td></tr>
</table>
</form>

<b>* <i>If you do not have a userid and password, please </i><a href="Registration Form.html">REGISTER</a>.</b><br>
<b>* <i>If you forgot your userid or password, please </i><a href="mailto:lyk@hushmail.com">email</a> me.</b>
</body>
</html>

home.html:-

<html>
<meta name="author" content="LYK">
<link rel=stylesheet href="stylesheet.css" type="text/css">
<head>
<title>Home Page</title>
</head>

<body >
<h1>Welcome to the HomePage!!!</h1>

</body>
</html>

Khalid Ali
07-20-2003, 10:02 AM
Here is simple login cookie script..let me know if you have problem implementing it...

http://68.145.35.86/skills/javascripts/SimpleLoginCookieScript.html

leong61
07-21-2003, 11:24 AM
Hello Khalid Ali,

I've seen your source code of the page you referred me to. However, I don't know which specific code to write to my home page?

Khalid Ali
07-21-2003, 11:28 AM
Everything is already there,the only thing you will have to do set the password and get the password in addition to the name which is already being stored and retrieved..Try the script and see if you can make any sense out if it and ask me questions about it