TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-19-2010, 05:41 PM   #1 (permalink)
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixed Mod_Rewrite with non trs21219 Advanced PHP Programming 5 01-15-2008 02:15 PM


All times are GMT. The time now is 01:28 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design