I'm practicing some php and I am creating this password system. my code doesn't work. anyone notices a mistake? I think it's just a stupid fault, but i can't seem to find it.
<?php
$passwords = array("name1" =>"pass1",
"name2" =>"pass2");
if ($password = $passwords[$username]){
setcookie("username", $username, time()+1200);
echo "<H2>Access granted.</H2>";
}
else{
setcookie("username", "", time()-3600);
echo "<H2>Invalid user name or password: access denied.</H2>";
}
?>
thanks everyone! my stupid fault was that i used = instead of == to check if $password is equal to $passwords[$username]