I have some simple static login PHP logic and trying to save the username in a cookie. Unfortunately, it doesn't save anything and also returns no errors, so I'm not really sure what's wrong. Maybe you can spot something in the code I'm doing wrong.
$users = array('allan'=>'allanpass');
$username = $_POST["username"];
$enterpass = $_POST["password"];
if(isset($_POST["username"])) {
if (array_key_exists($username, $users)) {
$pass = $users["allanpass"];
if($enterpass == $pass) {
setcookie("heyhey", 'user2', time() + 60 * 60 * 24 * 7, '/');
echo "Welcome back! <br />";
echo '<a href="login.php?link=link1">Link1</a><br />';
echo '<a href="login.php?link=link2">Link2</a><br />';
echo '<a href="login.php?link=link3">Link3</a><br />';
} else {
echo "pass does not exist";
}
} else {
array_push($users, $username);
echo "hello new user <br />";
echo '<a href="#">Link1</a><br />';
echo '<a href="#">Link2</a><br />';
echo '<a href="#">Link3</a><br />';
}
} else {
echo "Please fill in the form";
};
EDIT: I have no previous cookies saved. Everything is destroyed.