PHP - Retreive logins and password used by.htaccess

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:

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

Rouzz sur 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] 


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 (
Unable to initiate a DDE link with Excel
Changing the default path for recording MS Word documents