Way to get user name logged in with htaccess?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kipthegreat
Forum Newbie
Posts: 2
Joined: Thu Sep 22, 2005 12:28 pm

Way to get user name logged in with htaccess?

Post by kipthegreat »

I am new to PHP, please forgive me if this is a dumb question.. I have searched php.net and various php faqs and haven't been able to find this information...


I have a directory that contains all the admin scripts for my site. Currently it is protected by an htaccess file, which allows access to 2 different admins.

What I would like to do is determine, in PHP code, which admin is logged in--not for authentication, but so that they won't have to then select their user name from a combo box in order for PHP to know who is logged in (after they already entered username and password for htaccess). I've looked at $SESSION[] array but haven't had much luck.

Is this possible?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Could save the username off to a cookie using setcookie().

Assuming it's not an authentication requirement, PHP could just read in the cookie (once you make sure to filter it) and bypass the form. Hey presto... If the username needs to be changed to another - offer a link to the form (a non-bypassed version) or similar.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

$_SERVER['HTTP_AUTH_USER'] appears to be what you're looking for.
kipthegreat
Forum Newbie
Posts: 2
Joined: Thu Sep 22, 2005 12:28 pm

Post by kipthegreat »

Weirdan wrote:$_SERVER['HTTP_AUTH_USER'] appears to be what you're looking for.
Thanks!

That didn't quite work, but it got me on the right track... on my server it was $_SERVER['REMOTE_USER']. I'm not sure if that differs depending on server set up or not...
Post Reply