Well, I was reading up on how to do this HTTP-Authentication and found this sample code for it:
[php]
<?php
function authenticate() {
header('WWW-Authenticate: Basic realm="Test Authentication System"');
header('HTTP/1.0 401 Unauthorized');
echo "You must enter a valid login ID and password to access this resource\n";
exit;
}
if (!isset($_SERVER['PHP_AUTH_USER']) ||
($_POST['SeenBefore'] == 1 && $_POST['OldAuth'] == $_SERVER['PHP_AUTH_USER'])) {
authenticate();
} else {
echo "
Welcome: " . htmlspecialchars($_SERVER['PHP_AUTH_USER']) . "
";
echo "Old: " . htmlspecialchars($_REQUEST['OldAuth']);
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "
\n";
}
?>
[/php]
This was on the PHP.net site at: http://php.net/manual/en/features.http-auth.php
In their version, they check for the values and if not in place, they echo out the actual login form. But, in your
code, I did not see the form. Is the form later in the code? You can either echo the form as in the above
sample or use a flag to display the login form or not depending on the values. Did that make sense?
Also, since you are using headers to handle the HTTP control of the authentication, it is really done using the
server-to-browser system. This might be tracked somewhat, but, is not encrypted. So, I am not really sure
if it is better than a server-side login system with encryption. Here is another site that steps thru the code to
explain each part: http://www.hackingwithphp.com/15/4/3/authentication-over-http Might help you
understand each part of it.
Lastly, I did further reading on this form of authentication because I was told it is insecure. It seems that the
username and password is sent in normal text and can be hacked with ease. All of my reading states that you
need to use HTTPS if you want to use this form of authentication system. But, for your code project, we can
get it working for you if you wish to continue with it.