PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
if (!isset($PHP_AUTH_USER))
{
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
else
{
echo "<p>You have entered this username: $PHP_AUTH_USER<br>";
echo "You have entered this password: $PHP_AUTH_PW<br>";
echo "The authorization type is: $PHP_AUTH_TYPE<p>";
}
?>
I'm sure that this should work correctly (I am not outputting anything before the header), however I always get a 500 Internal Server Error.
Will HTTP-Authentication work in Windows?
The problem is likely to be that you should be using things like $_SERVER['PHP_AUTH_USER'] instead of $PHP_AUTH_USER - check the examples shown in the link above which have been written to work in the latest versions of PHP where register_globals (viewtopic.php?t=511) is off by default.