通过PHP HTTP认证 - PHP_AUTH_USER没有设置? [英] HTTP Auth via PHP - PHP_AUTH_USER not set?

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

问题描述

我试图通过HTTP实现小型认证和复制code这一点从网检查是否会正常工作:

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'] 从未设置!可能是什么问题?我运行Ubuntu 10.04 LTS服务器的Apache / 2.0.63(Unix的)了mod_ssl / 2.0.63的OpenSSL / 0.9.7d DAV / 2服务器

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,你可以pretty多少忘记它,因为是使用HTTP认证从PHP没有合理的方式。

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天全站免登陆