Search code examples
php.htaccess.htpasswd

how to get logged in user's name from .htpasswd?


I have a password protected directory with htaccess and htpasswd.

My .htpasswd file looks like this:

user1:passwordstring
user2:passwordstring
user3:passwordstring

When any of the user login successfully into the directory is there anyway I can get that user's name using php?


Solution

  • Assuming that I've understood the question correctly, your answer is here. More reference.

    <?php
    $username = $_SERVER['PHP_AUTH_USER'];
    $password = $_SERVER['PHP_AUTH_PW'];
    ?>