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

发布于 2024-11-01 08:47:21 字数 987 浏览 1 评论 0原文

嘿伙计们, 我又被卡住了,除了 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');
?>

有什么想法如何解决这个问题并使其正常工作吗?

提前致谢

Hey guys,
I'm stuck again, so where else to go than stackoverflow?
So heres the deal:
My site is set up and works fine on LOCALHOST. I have an admin section of my site - nothing too fancy, but have used basic http authentication to protect it.
I have just FTP'd the whole lot over to the LIVE HOST directory and low and behold the HTTP authentication doesn't work. Specifically, the username/password pop-up box appears with the correct details on it. However, when I type in the correct login details the box doesn't let me on the page, it just reappears empty.
The authentication script is a separate file:

<?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');
?>

Any ideas how to get round this and get it to work?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如若梦似彩虹 2024-11-08 08:47:21

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

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

I always used this for simple authentication, never had problems with it. But it looks very similar to yours.

<?
$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;
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文