05-19-2010, 09:38 PM
|
#2 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Consider the cases:
Code:
$_SERVER['PHP_AUTH_USER'] !== "username" && $_SERVER['PHP_AUTH_PW'] !== "password"
-----
Username valid, password invalid: FALSE && TRUE gives Authenticated
Username invalid, password valid: TRUE && FALSE gives Authenticated
Username valid, password valid: FALSE && FALSE gives Unauthorized!
Username invalid, password invalid: TRUE && TRUE gives Unauthorized!
$_SERVER['PHP_AUTH_USER'] !== "username" || $_SERVER['PHP_AUTH_PW'] !== "password"
-----
Username valid, password invalid: FALSE || TRUE gives Unauthorized!
Username invalid, password valid: TRUE || FALSE gives Unauthorized!
Username valid, password valid: FALSE || FALSE gives Authenticated
Username invalid, password invalid: TRUE || TRUE gives Unauthorized!
A perhaps clear option is to have the condition being not (username valid and password valid)...
PHP Code:
if ( ! ($_SERVER['PHP_AUTH_USER'] === "username" && $_SERVER['PHP_AUTH_PW'] === "password")) {
|
|
|
|