PHP Apache/PHP - grabbing a username from the login dialog

  • Thread starter Thread starter Hootenanny
  • Start date Start date
AI Thread Summary
A user successfully secured part of a site on a shared Apache server using the .htaccess file and sought assistance in displaying the logged-in username dynamically on the website. The recommended approach involves using PHP to retrieve the username with the code snippet $_SERVER["REMOTE_USER"], which is effective for most systems. An alternative method provided is $_SERVER['PHP_AUTH_USER'], with $_SERVER['PHP_AUTH_PW'] available for password retrieval. The user confirmed that the initial solution worked well and expressed gratitude for the alternatives offered.
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".
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Replies
12
Views
2K
Replies
15
Views
3K
Replies
7
Views
2K
Replies
5
Views
3K
Replies
4
Views
5K
Replies
4
Views
6K
Replies
1
Views
2K
Back
Top