Straight from PHP.Net:
Code:
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?> Here's the outcome:
http://www.ragadesign.com/authenticate.php .
The "
header('HTTP/1.0 401 Unauthorized');" bit causes error 500. Any clues to what's the issue? It works fine in my Apache / Windows text box, and it works fine in one Apache / Linux box I tried it with.
Are you using a CGI version of PHP, or what's the issue?
Oh yes, on error 500, a peculiar issue I noticed:
http://www.ragadesign.com/whatever.php
This non-existing page gives me error 500, though one'd expect error 404.
http://www.ragadesign.com/whatever.html
This non-existing page gives me 404 as always.
Am I missing something here? Is something messed up with my configuration (I haven't done any) or is it a server config issue?