Search code examples
php.htaccess.htpasswd

Login with htaccess + welcome message with php


I have a htaccess and htpasswd file. I want that if e.g.: user1 logs in give a message that Welcome 'user1'!

My main problem is that I don't know how to tell to the php file that user1 is logged in ...


Solution

  • I believe you can access the logged in user with this:

    $_SERVER['PHP_AUTH_USER']
    

    It's been a while since I last used it though

    if (isset($_SERVER['PHP_AUTH_USER']))
    {
        echo "Hello {$_SERVER['PHP_AUTH_USER']}!";
    }