I am trying to work through the authentication examples in the Welling/Thomson 3rd Edition of PHP and MySQL Web Development. This edition was supposed to be updated for PHP Version 5 but I am having many problems with the included codes.
I have installed PHP Version 5.1.6 on my machine and it is working. I am running it on an Apache Version Apache/2.0.54 (Win32) PHP/5.1.6
Apache API Version 20020903
Loaded Modules core mod_win32 mpm_winnt http_core mod_so mod_access mod_actions mod_alias mod_asis mod_auth mod_autoindex mod_cgi mod_dir mod_env mod_imap mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_setenvif mod_userdir mod_php5
The code I am trying to get working is as follows:
<?php
// if we are using IIS, we need to set $PHP_AUTH_USER and $PHP_AUTH_PW
if (substr($SERVER_SOFTWARE, 0, 9) == 'Microsoft' &&
!isset($PHP_AUTH_USER) &&
!isset($PHP_AUTH_PW) &&
substr($HTTP_AUTHORIZATION, 0, 6) == 'Basic '
)
{
list($PHP_AUTH_USER, $PHP_AUTH_PW) =
explode(':', base64_decode(substr($HTTP_AUTHORIZATION, 6)));
}
// Replace this if statement with a database query or similar
if ($PHP_AUTH_USER != 'user' || $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.';
}
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>';
}
?>
Based on that script shouldn't the user name be entered as "user" and the password entered as "pass"?
Everytime I try to enter those in the authentication window it rejects them. When I hit cancel it drops me to the "Go Away!" lines.
Are there some settings I need to check or has syntax changed on this type of script?
Thanks
I am new to PHP - makes it kind of tough when you are trying to work through a book and the examples don't work!