Stumped on PHP Authentication

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
techlinks
Forum Newbie
Posts: 18
Joined: Sun Dec 29, 2002 4:00 am

Stumped on PHP Authentication

Post by techlinks »

Hi. I'm totally stumped on why this code doesn't work on my server (hosted by POWWEB). When the bottom is executed, my user/pass dialog box never drops unless I hit cancel. Shouldn't it drop out from authenticating after I press the OK button followed by printing the name and password previously entered? I'm going through this exercise only because I consistently fail to evaluate $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'].

Can someone give me a hand pleaes?

Code: Select all

if (!isset($_SERVERї'PHP_AUTH_USER'])) {
   header('WWW-Authenticate: Basic realm="My Realm"');
   header('HTTP/1.0 401 Unauthorized');
   echo 'Text to send if user hits Cancel button';
   exit;
  } else {
   echo "<p>Hello &#123;$_SERVER&#1111;'PHP_AUTH_USER']&#125;.</p>";
   echo "<p>You entered &#123;$_SERVER&#1111;'PHP_AUTH_PW']&#125; as your password.</p>";
  &#125;
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

your logic is 'mistaken'

Code: Select all

if (!isset($_SERVER&#1111;'PHP_AUTH_USER'])) &#123;
   header('WWW-Authenticate: Basic realm="My Realm"');
   header('HTTP/1.0 401 Unauthorized');
&#125;

echo "<p>Hello &#123;$_SERVER&#1111;'PHP_AUTH_USER']&#125;.</p>";
echo "<p>You entered &#123;$_SERVER&#1111;'PHP_AUTH_PW']&#125; as your password.</p>";
&#125;
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

if (!isset($_SERVER&#1111;'PHP_AUTH_USER'])) &#123; 
   header('WWW-Authenticate: Basic realm="My Realm"'); 
   header('HTTP/1.0 401 Unauthorized'); 
&#125; 

echo "<p>Hello &#123;$_SERVER&#1111;'PHP_AUTH_USER']&#125;.</p>"; 
echo "<p>You entered &#123;$_SERVER&#1111;'PHP_AUTH_PW']&#125; as your password.</p>";
removed ending bracket
Post Reply