PHP - Retreive logins and password used by.htaccess

December 2016


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:

Note that

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] 


Related :

This document entitled « PHP - Retreive logins and password used by.htaccess » from CCM ( 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.