PHP - Retreive logins and password used by.htaccess

August 2017



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


Published by jak58. Latest update on April 19, 2011 at 10:05 AM by jak58.
This document, titled "PHP - Retreive logins and password used by.htaccess," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).