Forum Moderators: coopster

Message Too Old, No Replies

Getting Apache login username in PHP

Getting Apache login username in PHP

         

kevpatts

11:07 am on Jun 21, 2006 (gmt 0)

10+ Year Member



Hey,

I'm a little new to the concept of restricing sites by apache password login (using .htpasswd). What I need to know is once I've logged in using my apache login and index.php comes up, how do I get index.php to know what username was used to log in?

Regards,
Kevin

eelixduppy

12:15 pm on Jun 21, 2006 (gmt 0)



I don't think that this can be done, but I may be completely wrong. If I were you, I would create my own authentication process [webmasterworld.com]. You might also get some more information from the Apache Forum [webmasterworld.com].

Good luck!

coopster

1:35 pm on Jun 21, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, kevpatts.

Actually you might find the value in a $_SERVER variable. Many servers will populate a $_SERVER index with the authentication information [php.net], including the userid and plain text password:

$_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']

eelixduppy

1:38 pm on Jun 21, 2006 (gmt 0)



Wow...I didn't know that. Just looked it up now; interesting

kevpatts

2:36 pm on Jun 21, 2006 (gmt 0)

10+ Year Member



Actually, I just got it before I came back here. I used:

$user=apache_getenv("REMOTE_USER");

and all worked good. Thanks for the effort though.

Kevpatts