Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Authentication fails to authenicate

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
I am trying to protect a webpage with basic autentication, however (both on a local WAMP-server and on my providers server), I cannot get any authentication. Even with the following code which should, I assume, only check for the presence of any username, authentication is refused:

Code:
<?php
  if (!isset($_SERVER['PHP_AUTH_USER'])   ) {
    header('HTTP/1.1 401 Unauthorized');
    header('[URL unfurl="true"]WWW-Authenticate:[/URL] Basic realm="Bla"');
    exit('Must enter valid username and password to continue.');
  }
?>

This derived from the following (described as working):
Code:
<?php
  // User name and password for authentication
  $username = 'rock';
  $password = 'roll';

  if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
    ($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
    // The user name/password are incorrect so send the authentication headers
    header('HTTP/1.1 401 Unauthorized');
    header('[URL unfurl="true"]WWW-Authenticate:[/URL] Basic realm="Guitar Wars"');
    exit('<h2>Guitar Wars</h2>Sorry, you must enter a valid user name and password to access this page.');
  }
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top