Im creating a site with a basic login to use cookies ( this is a college assignment and so i don't need a registration page etc - i just need to show ive used cookies in the site) I have the below code:
login.htm
<table border="1" width="500px" height="400">
<tr>
<td> <center><h1>User Login </h1>
<form name="login" method="post" action="login1.php">
Username: <input type="text" name="username"><br><br><br>
Password: <input type="password" name="password"><br><br><br>
Remember Me: <input type="checkbox" name="rememberme" value="1"><br><br><br>
<input type="submit" name="submit" value="Login!">
</form></center> </td></tr></table>
login1.php
<?php
/* These are our valid username and passwords */
$user = 'louise';
$pass = 'password';
if (isset($_POST['username']) && isset($_POST['password'])) {
if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) {
if (isset($_POST['rememberme'])) {
/* Set cookie to last 1 year */
setcookie('username', $_POST['louise'], time()+60*60*24*365, '/htdocs', 'localhost');
setcookie('password', md5($_POST['password']), time()+60*60*24*365, '/htdocs', 'localhost');
} else {
/* Cookie expires when browser closes */
setcookie('username', $_POST['louise'], false, '/htdocs', 'localhost');
setcookie('password', md5($_POST['password']), false, '/htdocs', 'localhost');
}
header("Location: http://localhost/index.php");
} else {
echo 'Username/Password Invalid';
}
} else {
echo 'You must supply a username and password.';
}
?>
index.php
<?php
/* These are our valid username and passwords */
$user = 'louise';
$pass = 'password';
if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
if (($_POST['username'] != $user) || ($_POST['password'] != md5($pass))) {
header('Location: http://localhost/index.htm');
} else {
echo 'Welcome back ' . $_COOKIE['username'];
}
} else {
header("Location: http://localhost/index.htm");
}
?>
This does not work though - if i input an incorrect username/password that says ive input an incorrect username/password - thats ok. But if I inpuut the correct username and password which are louise and password there is nothing to say welcome louise.. it just goes back to the index.htm.. any ideas what im doing wrong?????