View Single Post
Old 05-19-2010, 05:41 PM   #1 (permalink)
skibbli
bajingo
 
skibbli's Avatar
 
Join Date: Feb 2010
Posts: 11
Thanks: 2
skibbli is on a distinguished road
Bug && and || are mixed up ?? :S

PHP Code:
if ($_SERVER['PHP_AUTH_USER'] !== "username" && $_SERVER['PHP_AUTH_PW'] !== "password") {
    
header('WWW-Authenticate: Basic realm="login"');
    
header('HTTP/1.0 401 Unauthorized');
    echo 
'<h2>Unauthorized!</h2>';
    exit;
}
echo 
"you are now authenticated."
the above code makes sense doesn't it? it really should work.

but upon further testing with that code above i have come to the conclusion that it will instead of requiring BOTH the username and password. it will only require one or the other...

HOWEVER, using "||" instead of "&&" will cause it to work the way i had originally intended it to work (requiring both fields to match using "&&" instead of one or the other)

PHP Code:
if ($_SERVER['PHP_AUTH_USER'] !== "username" || $_SERVER['PHP_AUTH_PW'] !== "password") {
    
header('WWW-Authenticate: Basic realm="login"');
    
header('HTTP/1.0 401 Unauthorized');
    echo 
'<h2>Unauthorized!</h2>';
    exit;
}
echo 
"you are now authenticated."
can anyone tell me why this may be?
could i have a small error in my code?
__________________
"Stealing! How could you? Haven't you learned anything from that guy who gives sermons at church? Captain what's-his-name?"
skibbli is offline  
Reply With Quote