由于更改托管,无法进行 PHP 身份验证
下面的代码用于对页面进行身份验证(它是整个页面的片段,但主要思想在这里):
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"MX Administration\"");
header("HTTP/1.0 401 Unauthorized");
exit;
}
else {
session_start();
if( $_SERVER['PHP_AUTH_USER'] == $login && md5($_SERVER['PHP_AUTH_PW'] ) == $password ){
if( $_SESSION['adm'] == '' && empty($_POST) ){
header("Location: whmcs.php");
exit;
}
elseif( $_SESSION['adm'] == '' && !empty($_POST) ){
if( $_POST['login'] == $login_in && md5($_POST['password']) == $password_in ){
$_SESSION['adm']="OK";
}
else{
header("Location: whmcs.php?do=message");
exit;
}
}
else{
$_SESSION['adm']="OK";
}
}
else{
header("WWW-Authenticate: Basic realm=\"MX Administration\"");
header("HTTP/1.0 401 Unauthorized");
echo ":)\n";
exit;
}
}
?>
现在,当我将此代码传输到另一台服务器时,它不会进行身份验证,它总是要求输入用户名、密码。我猜这是因为php版本,php配置。你的想法可能是什么原因。 (我确信我写的是正确的用户名和密码。)
The code blow was used for authenticatin for a page (it is snippet of whole page but the main idea is here):
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"MX Administration\"");
header("HTTP/1.0 401 Unauthorized");
exit;
}
else {
session_start();
if( $_SERVER['PHP_AUTH_USER'] == $login && md5($_SERVER['PHP_AUTH_PW'] ) == $password ){
if( $_SESSION['adm'] == '' && empty($_POST) ){
header("Location: whmcs.php");
exit;
}
elseif( $_SESSION['adm'] == '' && !empty($_POST) ){
if( $_POST['login'] == $login_in && md5($_POST['password']) == $password_in ){
$_SESSION['adm']="OK";
}
else{
header("Location: whmcs.php?do=message");
exit;
}
}
else{
$_SESSION['adm']="OK";
}
}
else{
header("WWW-Authenticate: Basic realm=\"MX Administration\"");
header("HTTP/1.0 401 Unauthorized");
echo ":)\n";
exit;
}
}
?>
Now when I have transfered this code to another server, it does not authenticate, it always asks for username, password. I guess it is because of php version, php config. What you think what may br the reason. (I am sure that I am writing the correct username and password.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的原因是 CGI API 用于运行 PHP 脚本。
您必须将 API 更改为 mod_php 或更改托管或将 HTTP 身份验证更改为会话
Most likely the reason is CGI API used to run PHP scripts.
You have to either change API to mod_php or change hosting or change HTTP auth to sessions