I'm trying to get the http authentication to work with a very simple little test program but I keep getting header errors. Here is the code:
<?
if (!$PHP_AUTH_USER || !$PHP_AUTH_PW)
{
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="admin"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
else
{
if($PHP_AUTH_USER == "stf" && $PHP_AUTH_PW == "stf")
{
echo"in";
}
else
{
echo"out";
}
}
?>
Here is the errors messages its generating:
Warning: Undefined variable: PHP_AUTH_USER in d:\apache\htdocs\admin.php on line 2
Warning: Cannot add header information - headers already sent by (output started at d:\apache\htdocs\admin.php:2) in d:\apache\htdocs\admin.php on line 5
Warning: Cannot add header information - headers already sent by (output started at d:\apache\htdocs\admin.php:2) in d:\apache\htdocs\admin.php on line 6
Authorization Required.
I've been working on trying to get this to work for a long time but nothing seems to fix it. Any suggestions?
Thanks,
stf