Hi,
I posted a reply to this yesterday and either you did see it, you didn't try the solution, or you replied and I didn't see your reply.
In any case, I'll explain the problem and give you the detailed solution.
First of all: you need to change that line to Header("Status: HTTP/1.1 401 Unauthorized"); You NEED the status... it's the ... right way :-)
Second of all, you need to let apache give you permission to allow http authentications. If you use webmin (www.webmin.com), configuring apache is easy and I can let you know what to click and set (post here again).
BUT: this is how you configure it by hand. In your httpd.conf file, add this line inside the Directory handler:
<Directory "/directory/to/your/auth/script">
Options ExecCGI (etc, etc... blah blah)
<b>AllowOverride AuthConfig</b>
</Directory>
Or if you want to allow all types of overrides, use "AllowOverride All".
If you use virtual servers, make sure you put those lines inside the virtual server config.
Now, restart apache (i'm not sure a SIGHUP would do the trick). Then reload the page. Usually you'll have to QUIT your browser and take it out again so that it doesn't load from cache.
Here is my sample script you can try AFTER you fix the apache configuration:
<?php
if ((!isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))) {
header( 'WWW-Authenticate: Basic realm="Private"' );
Header("Status: HTTP/1.1 401 Unauthorized");
echo 'Authorization Required.';
exit;
} else {
echo "You entered $PHP_AUTH_USER for a username.<BR>";
echo "You entered $PHP_AUTH_PW for a password.<BR>";
}
?>
-sridhar