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:
This derived from the following (described as working):
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.');
}
?>