Базовая аутентификация с PHP дает бесконечный цикл

For some reason I can't get Basic Authentication to work using PHP on my server. I am using the exact code from the manual page:

<?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>";
}
?>

However, when I run it, I can never get beyond the prompt.

If I put this same code on my other server, it works fine.

Does anyone know what could be causing this? Both servers are WAMP stacks and Apache has the auth_basic_module enabled. The PHP.ini files are practically identical as well.

I glanced at the headers and after I enter my username/password, there is the "Authorization: Basic XXXXXX" header being sent.

7
задан Brandon0 8 February 2011 в 00:11
поделиться