chpicker
Programmer
- Apr 10, 2001
- 1,316
I cannot seem to get PHP Authentication to work. I tried the example given in the PHP documentation, and that doesn't work, either. Here is what I tried:
When I attempt to run this page from my web site, the authentication dialog pops up as expected...three times, followed by the 'Text to send if user hits Cancel button' page, which was NOT expected.
My web server is running PHP 4.3.3 under Apache. I don't know if it is running as a server module or CGI, though, and I think that might be my problem. However, I don't know what the behavior would be in that case. Can anyone confirm this? If that's not the problem, does anyone have any ideas?
Thanks,
Ian
Code:
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('[URL unfurl="true"]WWW-Authenticate:[/URL] 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>";
}
?>
My web server is running PHP 4.3.3 under Apache. I don't know if it is running as a server module or CGI, though, and I think that might be my problem. However, I don't know what the behavior would be in that case. Can anyone confirm this? If that's not the problem, does anyone have any ideas?
Thanks,
Ian