设为首页收藏本站

数码鹭岛论坛

 找回密码
 注-册

QQ登录

只需一步,快速开始

搜索
查看: 8284|回复: 2
打印 上一主题 下一主题

HTTP Authentication with PHP running as CGI

[复制链接]
跳转到指定楼层
1#
发表于 2008-10-19 22:56:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
While developing a project using two factor authentication, with a key fob, I needed to use HTTP Basic Authentication over SSL, to prevent XSS as the project was a web based proxy. Now I had PHP5 running as a module, but PHP4 as CGI. There was the problem HTTP Authentication isn’t available under PHP running as CGI.

First you need to configure mod_rewrite:

.htaccess:

RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

What that will do is feed the base64′d user:pass into an environment variable named HTTP_AUTHORIZATION.

Then just add this above your script:

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(’:’ , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

That splits up the username and password, and makes it look as if you were running PHP as a module.
So for a sample script:

<?
// split the user/pass parts
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(’:', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

// open a user/pass prompt
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 ‘Hello, ‘.htmlentities($_SERVER['PHP_AUTH_USER']).’

‘;
echo ‘You entered as your password: ‘.htmlentities($_SERVER['PHP_AUTH_PW']).’

‘;
}
?>
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2#
 楼主| 发表于 2008-10-19 23:02:24 | 只看该作者

zeus Request Rewriting

RULE_0_START:
match URL into $ with .*
if not matched then goto RULE_0_END
# Source line 2
# Second half of: RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
set ENV:HTTP_AUTHORIZATION = %{IN:Authorization}
# This rule has [L]
goto END
RULE_0_END:
3#
 楼主| 发表于 2008-10-19 23:05:57 | 只看该作者
http://support.zeus.com/zws/integration/2005/12/16/zope
here says:
.htaccess

<Location /zope/>
PassEnvAuthorization on
</Location>

but not work for me. it deny all access. i even try Restricting Access Rule.
您需要登录后才可以回帖 登录 | 注-册

本版积分规则

小黑屋|手机版|Archiver|数码鹭岛 ( 闽ICP备20006246号 )  

counter

GMT+8, 2025-12-4 06:13 , Processed in 0.068998 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表