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

时间:2011-04-13 12:10:11

标签: php http authentication http-headers authorization

嘿伙计们, 我再次陷入困境,那么除了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');
?>

任何想法如何绕过这个并让它发挥作用?

提前致谢

1 个答案:

答案 0 :(得分:0)

我总是将它用于简单的身份验证,从来没有遇到过问题。但它看起来与你的非常相似。

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