I am currently trying to create a php cookie logon for a university website I have been using the following code but cant seem to get to operate......Please help:
<?php
// valid login credentials
$username = 'admin';
$password = 'admin_pass';
// grab current time
$time=time();
// handle the logout event
if ($logout == true) {
setcookie ("user", md5($POST[user]), $time-3200);
setcookie ("pass", md5($POST[pass]), $time-3200);
header("Location: index.php");
}
// handle validation event
if ($POST[user] && $POST[pass]) {
if ($POST[user]==$username && $POST[pass]==$password) {
setcookie ("user", md5($POST[user]), $time+3200);
setcookie ("pass", md5($POST[pass]), $time+3200);
header("Location: index.php");
} else { $login_error= true; }
}
// handle login event, both successful and erroneous, or show login screen
if ($login_error == true) { ?>
<table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
<tr><td align=center bgcolor=#123dd4>LOGIN ERROR</td></tr>
<tr><td align=center><b>Invalid Username and/or Password</b><br><br><a href=index.php>Back</a></td></tr>
</table>
<?
} elseif ($COOKIE[user] == md5($username) && $COOKIE[pass] == md5($password)) { ?>
<table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
<tr><td align=center bgcolor=#123dd4>SECURE AREA</td></tr>
<tr><td align=right><a href=index.php?logout=true>Logout</a></td></tr>
<tr><td>You have successfully logged in.<br><br>
Encrypted Username: <b><?= $COOKIE[user] ?></b><br>
Encrypted Password: <b><?= $COOKIE[pass] ?></b><br>
</td></tr>
</table>
<?
} else {
?>
<form action=index.php method=post>
<table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
<tr><td colspan=2 align=center bgcolor=#123dd4>LOGIN</td></tr>
<tr><td align=right>Username: </td><td><input type=text name=user size=15></td></tr>
<tr><td align=right>Password: </td><td><input type=password name=pass size=15></td></tr>
<tr><td align=center colspan=2><input type=submit value=Login></td></tr>
</table>
</form>
<?
}
?>