如何用PHP作为CGI运行填充$ _SERVER ['Remote_User']变量?

时间:2013-02-01 07:39:54

标签: php windows cgi username

我徒劳地试图让变量$_SERVER['Remote_User']来验证我的内部应用程序的用户。

有没有办法用PHP作为CGI运行?

我尝试了googeling时发现的所有workarrounds(重写规则,在.htaccess中设置变量,然后爆炸b64编码的字符串)。

或者是否有其他一些天真的方式来获取访问我网站的人的用户名?

这是我的$ _SERVER数组的打印输出:

Array
(
[HTTP_HOST] => tnxp.telenor.net
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_CONNECTION] => keep-alive
[HTTP_CACHE_CONTROL] => max-age=0
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] => 
Apache/2.2.15 (Red Hat) Server at tnxp.telenor.net Port 80


[SERVER_SOFTWARE] => Apache/2.2.15 (Red Hat)
[SERVER_NAME] => tnxp.telenor.net
[SERVER_ADDR] => 10.179.98.20
[SERVER_PORT] => 80
[REMOTE_ADDR] => 148.121.183.28
[DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => root@localhost
[SCRIPT_FILENAME] => /var/www/html/ew/index.php
[REMOTE_PORT] => 50315
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /ew/
[SCRIPT_NAME] => /ew/index.php
[PHP_SELF] => /ew/index.php
[PHP_AUTH_USER] => t820082
[PHP_AUTH_PW] => asdf
[REQUEST_TIME_FLOAT] => 1359703708.68
[REQUEST_TIME] => 1359703708
)

理想情况下,我希望这包含[REMOTE_USER] => 客户用户名

任何帮助表示赞赏!!

2 个答案:

答案 0 :(得分:0)

$_SERVER变量是您不应该设置的。它们在加载脚本时由服务器设置,并在下次加载时重置。

使用sessions代替(如果需要,还可以使用单独的类来处理纯CGI中的会话 - 只需谷歌CGI会话 - 那里有大量文档。)

答案 1 :(得分:0)

也许是这样的?

$loginName = substr($loginName, 0, 2).strToLower(substr($loginName, 2));



$authorizedUserList = Array();

$authorizedUserList[] = "user1";

$authorizedUserList[] = "user2";

$authorizedUserList[] = "user3";

$authorizedUserList[] = "user4";
forEach($authorizedUserList as $authorizedUser){

    if(strToUpper($authorizedUser) == strToUpper($loginName)){

        $authCheckPass = true;

    }

}