HTTP Auth via PHP - PHP_AUTH_USER not set?
Run phpinfo(). if "Server API" is CGI/FCGI, you can pretty much forget it as there is no sensible way to use HTTP auth from PHP.
Why are $_SERVER[PHP_AUTH_USER] and $_SERVER[PHP_AUTH_PW] not set?
I've finally discovered the answer thanks to the of help of Naktibalda in ##php on irc.freenode.net
The following page summarises the issue: http://php.net/manual/en/features.http-auth.php
To quote the relevant bits:
As of PHP 4.3.0, in order to prevent someone from writing a script which reveals the password for a page that was authenticated through a traditional external mechanism, the PHP_AUTH variables will not be set if external authentication is enabled for that particular page and safe mode is enabled. Regardless, REMOTE_USER can be used to identify the externally-authenticated user. So, you can use $_SERVER['REMOTE_USER'].
...
PHP uses the presence of an AuthType directive to determine whether external authentication is in effect.
Http Auth dosen't work with PHP
The problem is solved.
I checked phpinfo() on our Server and SERVER API was on CGI/FastCGI.
HTTP Auth via PHP - PHP_AUTH_USER not set?
Run phpinfo(). if "Server API" is CGI/FCGI, you can pretty much forget
it as there is no sensible way to use HTTP auth from PHP.
Now I knew where the problem is and I solved the Issue while adding the following part into my public/.htacces .
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
$_SERVER['PHP_AUTH_USER'] is empty
I finally found the answer thanks to 'mbinette'.
In my PHP configuration, the handler of PHP 5 was CGI, and this type of authentication doesn't work with PHP CGI. So i changed it to suPHP (which is supposed to be the default one on APACHE).
Find here a post explaining a way to use CGI and PHP_AUTH, but i tried and it wasn't working.
Find here some explanations about php handlers
Related Topics
How to Convert JSON to Xml in PHP
Sorting Laravel Collection via Array of Id'S
Phpmyadmin - Count(): Parameter Must Be an Array or an Object That Implements Countable
How to Render a Datetime Object in a Twig Template
Dynamic Class Method Invocation in PHP
PHP and Mod_Fcgid: Ap_Pass_Brigade Failed in Handle_Request_Ipc Function
Checking If All the Array Items Are Empty PHP
Best Way to Create an Empty Object in JSON with PHP
Cloudflare and Logging Visitor Ip Addresses via in PHP
How to Logout from a Session in PHP
Multidimensional Array Array_Sum
How to Use Pdo's Prepared Statement for Order by and Limit Clauses
What Is Your Preferred PHP Deployment Strategy
How to Check and Set Max_Allowed_Packet MySQL Variable
Passing a Variable from One PHP Include File to Another: Global VS. Not