切换到LIVE主机时,HTTP身份验证不起作用


HTTP authentication not working when switched to LIVE host

大家好!我又卡住了,除了stackoverflow还能去哪里?所以事情是这样的:我的网站设置和工作在LOCALHOST上很好。我有我的网站的管理部分-没有太花哨,但已经使用基本的http身份验证来保护它。我刚刚用FTP将所有内容传输到LIVE HOST目录,然后发现HTTP身份验证不起作用。具体来说,用户名/密码弹出框将显示正确的详细信息。但是,当我输入正确的登录详细信息时,该框不允许我进入页面,它只是重新显示为空。身份验证脚本是一个单独的文件:

<?php
 // User name and password for authentication
 $username = 'USER';
 $password = 'PASSWORD';
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
// The user name/password are incorrect so send the authentication headers
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="The Manor Cheadle"');
exit('<h2>The Manor Cheadle</h2>Sorry, you must enter a valid user name and 
password to access this page.');
}
?>
and is referenced at the top of every page:
<?php
require_once('authorize.php');
?>

有什么办法绕过这个问题,让它工作吗?

Thanks in advance

我一直用它来进行简单的身份验证,从来没有遇到过问题。但是它看起来和你的很像。

<?
$auth = 0;
if (!isset($_SERVER['PHP_AUTH_USER']))
{
    header('WWW-Authenticate: Basic realm="Login"');
    header('HTTP/1.0 401 Unauthorized');
    print "you need to login";
    exit;
}
else
{
    if ($_SERVER['PHP_AUTH_USER'] == "UserName" and $_SERVER['PHP_AUTH_PW'] == "Password")
    {
        $auth=1;
    }
    else
    {
        header('WWW-Authenticate: Basic realm="Login"');
        header('HTTP/1.0 401 Unauthorized');
        print "you need to login";
        exit;
    }
}
if ($auth==0) {
    print "you need to login";
    exit;
}
?>