Apache/PHP - grabbing a username from the login dialog

  • Topic: PHP 
  • Thread starter Thread starter Hootenanny
  • Start date Start date
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
3 replies · 3K views
Staff Emeritus
Science Advisor
Gold Member
Messages
9,621
Reaction score
9
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.
 
Physics news on Phys.org
Hi Ho!

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


Eus
 
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".