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

I am trying in vain to get the variable $_SERVER['Remote_User'] to authenticate users of my inhouse-app.

Is there any way to do this with PHP running as CGI?

I have tried all the workarrounds that i found while googeling (rewrite-rules that sets the variable in .htaccess and then explodes a b64 encoded string).

Or is there some other genious way to get the user-name of the person visiting my site?

Here is a print-out of my $_SERVER array:

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
)

Ideally i would like this to contain [REMOTE_USER] => clients username

Any help is appreciated!!

$_SERVER variables are something you shouldn't set. They are set by server when script is loaded and will be reset on next load.

Use sessions instead (there's also separate class for handling sessions in pure CGI if you need it - just google CGI Sessions - lots of documentation there).

Maybe something like this?

$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;

    }

}