Link to home
Start Free TrialLog in
Avatar of denverwayne
denverwayne

asked on

Problem with http basic authentication

I am having trouble getting basic authentication, so I wrote this simple file which I was hoping would reveal why.

     1  <?php
     2
     3  if (!isset($_SERVER['PHP_AUTH_USER'])) {
     4    header ('WWW-Authenticate: Basic realm="Basic Auth Test"');
     5    header ('HTTP/1.0 401 Unauthorized');
     6    die ("Was the Cancel button pressed?");
     7  }//end if
     8
     9  echo "\nOk, we have a value! Let's dump the \$_SERVER global array!\n\n";
    10  var_dump($_SERVER);
    11  echo "\n\nFinished!\n";
    12
    13  ?>
    14

It should open an 'Authentication Required' window requesting a user name and password, but should accept whatever is entered. However, the window appears as expected, but when the fields are filled and OK is clicked, it vanishes for a very brief time, then reappears. Seems the entries are not being kept in the $_SERVER['PHP_AUTH_USER'] array.

The server is running Centos 6.5 and Plesk 12

I tried running the script on another server with Centos 6.4 with no GUI, and it works fine when I browse it.

Kind of making me crazy. Hope someone can help.

Wayne
Avatar of Hagay Mandel
Hagay Mandel
Flag of Israel image

Use
if(isset($_SERVER['PHP_AUTH_USER'])){
  var_dump($_SERVER['PHP_AUTH_USER']);
}

Open in new window

at the very beginning of the code, to find out what is really kept there.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of denverwayne
denverwayne

ASKER

OK, thanks. Finally got it!