This script uses frames to write two pages to the current window. they must be named authorize.html and login.html. Only login.html will be visible to the user. authorize.html contains hidden variables and are asigned values as upon login. When a login is accepted, 'granted' is assigned to the hidden access variable in authorize.html. All the protected pages have to look for is if this variable =='granted'.
The member username was also assigned to a hidden variable called user and was printed to test1.html. You can also collect all other sorts of information this way.
Codes:
authorize.html:
<html>
<body>
<form name="m">
<input name="user" type="hidden">
<input name="access" type="hidden">
</form>
</body>
</html>
login.html:
<SCRIPT LANGUAGE="JavaScript">
<!--
function Login(){
var done=0;
var username=document.f.user.value;
username=username.toLowerCase();
var password=document.f.pass.value;
password=password.toLowerCase();
if (username=="member" && password=="pass") { window.location="test1.html"; done=1; parent.frames.m.document.m.access.value="granted";}
if (done==0) { alert("Incorrect password"); }
}
//-->
</SCRIPT>
<input name="user" type="text" value="member">
<input name="pass" type="text" value="pass">
<input type="button" onclick="Login()" value="Login">
A protected page:
<script language="Javascript">>
<!--
if(parent.frames.m.document.m.access.value=="denied"){
location.href="login.html";
}
function logout(){
parent.frames.m.document.m.access.value="denied";
location.href="login.html";
}
//-->
</script>
<a href="Javascript:logout()">Logout</a>
|