Zend Server Windows - 授权头信息未传递至 PHP 脚本

3

我有一个PHP应用程序,需要独立于包含的Apache服务器执行HTTP基本身份验证。

在安装了通过apt-get php的php的linux机器上,我发现Authorization标头不会出现在$_SERVER中,但可以通过apache_request_headers()getallheaders()获得。

在一个Windows开发机上,使用Zend Server 6.1.0 / PHP 5.4,我无法通过上述任何方法从PHP内部获取Authorization标头的值。如何获取它的值?

mod_fcgid?

我还没有确定这一点,但似乎Zend Server可能使用FCGI将Apache请求分派给PHP(例如,在$_SERVER中出现变量PHP_FCGI_MAX_REQUESTS)。

如果是这样,这就解释了我的问题,因为mod_fcgid有意将Authorization标头从应用程序中保留,参见http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidpassheader

我尝试添加:

FcgidPassHeader Authorization

我尝试将内容添加到我的apache的 httpd.conf 文件中,但程序提示出错:
Invalid command 'FcgidPassHeader', perhaps misspelled or defined by a module not included in the server configuration

mod_fastcgi是什么?

同样地,也许Zend正在使用mod_fastcgi?根据这个页面http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiConfig,我尝试在我的apache httpd.conf中添加以下内容:

FastCgiConfig -pass-header Authorization

再次强调,它只是抱怨说:

Invalid command 'FastCgiConfig', perhaps misspelled or defined by a module not included in the server configuration
1个回答

19

我发现可以通过在 Windows 上的 Apache 配置中添加以下内容来解决这个问题:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

这将向$_SERVER全局变量添加一个HTTP_AUTHORIZATION密钥,就像Apache传递了Authorization头文件一样。


有人能解释一下为什么需要这个解决方法吗? - Janis Peisenieks
我认为大多数 PHP SAPI 默认情况下会保留“Authorization”标头,“出于安全考虑”。 - Rich

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接