login.php
- Code: Select all
<?php
$cookie = $_COOKIE["user"];
if ($cookie=="user1")
{
header('Location: home.php');
}
else if ($cookie=="user2")
{
header('Location: home.php');
}
else
{}
?>
<html>
<body>
<center>
<form id="login" method="post" action="check.php">
<table border="1">
<tr>
<td colspan="2">
<h3><b><center>Login</center></b></h3>
</td>
</tr>
<tr>
<td>
Username:
</td>
<td>
<input type="text" id="user">
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" id="pass">
</td>
</tr>
<tr>
<td colspan="2">
<center>
<input type="submit" value="Submit">
</center>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
check.php
- Code: Select all
<?php
$expire=time()+60*59;
if ($_POST["user"]=="user1" AND $_POST["pass"]=="password1")
{
header('Location: home.php');
setcookie("user", "user2");
}
else if ($_POST["user]=="user2" AND $_POST["pass"]=="password2")
{
header('Location: home.php');
setcookie("user", "user1")
}
else
{
header('Location: fail.php');
}
?>
<html>
<head>
<style type="text/css">
.red
{
color: red
}
</style>
</head>
<body>
<center><span class="red">Validating input...</span></center>
</body>
</html>
home.php
- Code: Select all
<?php
$cookie = $_COOKIE["user"];
if ($cookie=="user1")
{}
else if ($cookie=="user2")
{}
else
{
header('Location: login.php');
}
?>
<html>
<body>
<span>Congrats! You made it!</span>
</body>
</html>