Apache/PHP - grabbing a username from the login dialog

  • Context: PHP 
  • Thread starter Thread starter Hootenanny
  • Start date Start date
Hootenanny
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.
 
on Phys.org
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:
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".
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K