通过 PHP 进行 HTTP 身份验证 - PHP_AUTH_USER 未设置? [英] HTTP Auth via PHP - PHP_AUTH_USER not set?

查看:39
本文介绍了通过 PHP 进行 HTTP 身份验证 - PHP_AUTH_USER 未设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过 http 实现一个小的身份验证,并从网上复制了这段代码以检查它是否可以正常工作:

I tried to implement a small authentication via http and copied this bit of code from the net to check whether this will work properly:

<?php
    if(!isset($_SERVER['PHP_AUTH_USER'])) {
        header('WWW-Authenticate: Basic realm="My Realm"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Text to send if user hits Cancel button';
        exit;
    } else {
        echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
        echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
    }
?>

然而,我的浏览器总是要求输入用户名和密码,但在我取消之前从不输出任何内容.因此我认为 $_SERVER['PHP_AUTH_USER'] 永远不会被设置!可能是什么问题?我正在使用 Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7d DAV/2 Server 运行 Ubuntu 10.04 LTS 服务器.

However, my browser always ask for a username and password but never outputs anything until i cancel. Therefore i think that $_SERVER['PHP_AUTH_USER'] is never set! What might be the problem? I am running Ubuntu 10.04 LTS Server with Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7d DAV/2 Server.

推荐答案

运行 phpinfo().如果服务器 API"是 CGI/FCGI,您几乎可以忘记它,因为没有合理的方法可以从 PHP 使用 HTTP 身份验证.

Run phpinfo(). if "Server API" is CGI/FCGI, you can pretty much forget it as there is no sensible way to use HTTP auth from PHP.

这篇关于通过 PHP 进行 HTTP 身份验证 - PHP_AUTH_USER 未设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆