Is there something wrong in PHP5 with the following?
{
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
explode(':', base64_decode(substr($HTTP_AUTHORIZATION, 6)));
}
This if from a page posted at www.testing.lane-consulting.com/16/http.php5
I cannot get the defined logins to work. It should be "user" and "pass" to get into the page, but it doesn't accept them.
The page code is as follows, any idea where I am going wrong?
<?php
// if we are using IIS, we need to set $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']
if (substr($SERVER_SOFTWARE, 0, 9) == 'Microsoft' &&
!isset($_SERVER['PHP_AUTH_USER']) &&
!isset($_SERVER['PHP_AUTH_PW']) &&
substr($HTTP_AUTHORIZATION, 0, 6) == 'Basic ' )
{
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
explode(':', base64_decode(substr($HTTP_AUTHORIZATION, 6)));
}
// Replace this if statement with a database query or similar
if ($_SERVER['PHP_AUTH_USER'] != 'user' || $_SERVER['PHP_AUTH_PW'] != 'pass')
{
// visitor has not yet given details, or their
// name and password combination are not correct
header('WWW-Authenticate: Basic realm="Realm-Name"');
if (substr($SERVER_SOFTWARE, 0, 9) == 'Microsoft')
header('Status: 401 Unauthorized');
else
header('HTTP/1.0 401 Unauthorized');
echo '<h1>Go Away!</h1>';
echo 'You are not authorized to view this resource.';
phpinfo();
}
else
{
// visitor has provided correct details
echo '<h1>Here it is!</h1>';
echo '<p>I bet you are glad you can see this secret page.</p>';
phpinfo();
}
?>
Thanks for any help or ideas! 😕