You are here : Home - Web Development - PHP - Password Protect - Login
Password Protect - Login
copy and save as index.php
<html>
<head>
<title>Login Page
</title>
</head>
<body bgcolor="white">
<table width="400" align="center">
<tr>
<th valign=top> private area
</th>
</tr>
<tr>
<td>
<p>This is a private area.
</p>
<p>Please log in below if you have access to this area
</p>
<?
//if no cookie is set then display the form
if(!isset($_COOKIE["this_cookie"])){
echo '<div align="center"><form action="validate.php" method="post">';
echo 'username : <input type="text" name="username"><br><br>';
echo 'password : <input type="password" name="password"><br><br>';
echo '<input type="submit" value="login"></form></div>';
}else{
echo "You are already logged in. <a href=\"1.php\">Continue</a>";
}
?>
</td>
</tr>
</table>
</body>
</html>
Nothing special about the form except that is written using php. This line
if(!isset($_COOKIE["this_cookie"])){ basically means, if the cookie isn't set then write the form or else write a link text.
Next we'll look at the validation script.
overview
the theory
the login
validation
a protected page
the logout