Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Apache/PHP - grabbing a username from the login dialog

  1. Feb 19, 2008 #1

    Hootenanny

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I've secured part of a site using the .htaccess file on a [shared] Apache server. Would it be possible to write a PHP (or java) script that would grab the username from the login dialog? I want to display it dynamically on the website as "You are logged in as [username]".

    Any help would be much appreciated.
     
  2. jcsd
  3. Feb 19, 2008 #2
    Try this

    $auth_username = $_SERVER["REMOTE_USER"];

    Note if there is a strange PHP configuration this might not work, but for 99% of systems it should.

    This is also a good page for you
    http://us2.php.net/features.http-auth
     
    Last edited: Feb 19, 2008
  4. Feb 20, 2008 #3

    Eus

    User Avatar

    Hi Ho!

    This one will work: $_SERVER ['PHP_AUTH_USER'].
    For the password: $_SERVER ['PHP_AUTH_PW'].

    Best regards,
    Eus
     
  5. Feb 20, 2008 #4

    Hootenanny

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Thanks Greg, it worked a treat!

    Thanks to Eus for your alternatives, I'll give them a go if anything goes wrong with "REMOTE_USER".
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Apache/PHP - grabbing a username from the login dialog
  1. PHP Help ? (Replies: 16)

  2. Php or c++ ? (Replies: 40)

  3. Perl & Apache (Replies: 6)

Loading...