Page 1 of 1

Stumped on PHP Authentication

Posted: Mon Jan 31, 2005 2:15 am
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;

Posted: Mon Jan 31, 2005 6:13 am
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;

Posted: Mon Jan 31, 2005 8:53 am
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