简体   繁体   English

HTTP验证,PHP 5.3

[英]http authentication, php 5.3

I like this simple http authenticating for some non-critical pages. 我喜欢对一些非关键页面进行简单的http身份验证。

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
  header('WWW-Authenticate: Basic realm="My Realm"');
  header('HTTP/1.0 401 Unauthorized');
  echo 'Text, der gesendet wird, falls der Benutzer auf Abbrechen drückt';
  exit;
} else {
  echo "<p>Hallo {$_SERVER['PHP_AUTH_USER']}.</p>";
  echo "<p>Sie gaben {$_SERVER['PHP_AUTH_PW']} als Passwort ein.</p>";
}
?>

Now I am trying to implement it on server with php 5.3 and it doesnt work. 现在,我试图用php 5.3在服务器上实现它,但它不起作用。 Whats wrong? 怎么了?

I type name and password, press enter and pages show me dialog again. 我输入名称和密码,按Enter键,页面再次显示对话框。 No values in $_SERVER['PHP_AUTH_USER']. $ _SERVER ['PHP_AUTH_USER']中没有值。

I am experiencing the same problem. 我遇到了同样的问题。 According to me service provider, this is an old version of php that doesn't work on php 5.5 & higher. 根据我的服务提供商的说法,这是php的旧版本,不能在php 5.5及更高版本上使用。 You will have to find a newer version of php. 您将必须找到更新版本的php。

From the HTTP Authentication with PHP page on php.net: 从php.net上的“ HTTP Authentication with PHP”页面:

As of PHP 4.3.0, in order to prevent someone from writing a script which reveals the password for a page that was authenticated through a traditional external mechanism, the PHP_AUTH variables will not be set if external authentication is enabled for that particular page and safe mode is enabled. 从PHP 4.3.0开始,为了防止某人编写脚本来显示通过传统外部机制进行身份验证的页面的密码,如果对该特定页面启用了外部身份验证且安全,则将不设置PHP_AUTH变量模式已启用。 Regardless, REMOTE_USER can be used to identify the externally-authenticated user. 无论如何,REMOTE_USER均可用于标识外部认证的用户。 So, you can use $_SERVER['REMOTE_USER']. 因此,您可以使用$ _SERVER ['REMOTE_USER']。

Perhaps this applied to this case. 也许这适用于这种情况。 (just noticed this is an old question :) (只是注意到这是一个老问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM