切换到 LIVE 主机时 HTTP 身份验证不起作用
嘿伙计们, 我又被卡住了,除了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我总是用它来进行简单的身份验证,从来没有遇到过问题。但它看起来和你的很相似。
I always used this for simple authentication, never had problems with it. But it looks very similar to yours.