PHP - Retreive logins and password used by.htaccess

December 2016



Intro


If you protected folder of your site using a.htaccess and you want to retrieve the login and password that the user has entered your PHP pages , you can use these variables:

$_SERVER['PHP_AUTH_USER'] // for login 
$_SERVER['PHP_AUTH_PW'] // for password 



Note that it work with PHP 5.
For PHP 4, use the variable:
$REMOTE_USER

Note that


Few people have figured out how to get a login via .htaccess on OVH shared hosting.

Rouzz sur www.z-f.fr has a solution:

OVH used PHP via SGI scripts and not as an Apache module and doesn't take Authorization header into consideration.
Add these 2 lines to .htaccess:
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L] 

echo $_SERVER['REMOTE_USER']; 



Related :

This document entitled « PHP - Retreive logins and password used by.htaccess » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.