Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Authentication with PHP running as FCGI

I Cannot get the basic HTTP Authentication to work in PHP which is installed and working as FCGI. It works perfectly when PHP is installed as a module though.

Is there any way I can get it to work ???

I am running PHP Version 5.2.6 in ubuntu.

<?Php 
if ( !$_SERVER['PHP_AUTH_USER'] ) {
    $this->getResponse()->setHeader('WWW-Authenticate',  'Basic realm="Testing"');
    $this->getResponse()->setBody('Unauthorized');
    $this->getResponse()->setHttpResponseCode(401);
} else { 
    var_dump($_SERVER['PHP_AUTH_USER']);
    var_dump($_SERVER['PHP_AUTH_PW']);
}  

I did try

[Rewrite rule on .htaccess]
 RewriteEngine on
 RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]

[user:pass on PHP-script]
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':',     base64_decode(substr($_SERVER['REDIRECT_REMOTE_USER'], 6)));

but it doesnt seem to be working.

like image 647
ro ko Avatar asked Oct 25 '25 02:10

ro ko


1 Answers

Delete your .htaccess and write a new one with this line:

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

and your PHP will work fine.

like image 72
Peter Kalef ' DidiSoft Avatar answered Oct 26 '25 17:10

Peter Kalef ' DidiSoft