Apache/PHP - grabbing a username from the login dialog

  • Context: PHP 
  • Thread starter Thread starter Hootenanny
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around retrieving a username from a login dialog on a secured Apache server using PHP. Participants explore methods to dynamically display the logged-in username on a website.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant inquires about the feasibility of using a PHP or Java script to capture the username from the login dialog for display purposes.
  • Another participant suggests using the variable $_SERVER["REMOTE_USER"] to obtain the username, noting potential issues with certain PHP configurations.
  • A third participant proposes an alternative method using $_SERVER['PHP_AUTH_USER'] to access the username, and mentions $_SERVER['PHP_AUTH_PW'] for the password.
  • A later reply confirms the success of the first suggestion and expresses willingness to try the alternative methods if needed.

Areas of Agreement / Disagreement

Participants present multiple methods for retrieving the username, with no consensus on a single best approach, as different configurations may affect functionality.

Contextual Notes

There are potential limitations related to PHP configurations that may impact the effectiveness of the suggested methods.

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.
 
Technology news 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
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K