We help IT Professionals succeed at work.

Extracting remote user name in script

newmang
newmang asked
on
I have a web page incorporating a form. This web page resides in a directory that is protected by apache using a </Directory> stanza so the client user must have supplied a username and password to have accessed the web page and form.

I want to be able to extract the username used to access the web page within the script called by the form.

The apache doco indicates that this should be passed as an environment variable but I am unable to make this work, presumably due to some server mis-configuration.

How do I accomplish this requirement?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
newmang,

".., presumably due to some server mis-configuration.

                     How do I accomplish this requirement? ..."

Based on your comments, it looks like you are certain the problem is due to Apache web server misconfiguration.

Therefore, i would suggest you post your question in the "Apache" topic area (http://www.experts-exchange.com/apache/). After you have resolved the mis configuration issue, you can always come back here and get the name of the environment variable.

Hope that helps.

Commented:
Hello there,
 You can get the values of USER by the environment variable
 USER_NAME. If the user has logged using HTTP authentication mechanism (.htaccess / .htpasswd), you can get the value of username by

 $ENV{'USER_NAME'}



Master Gaurav
http://sf.net/users/mastergaurav
http://home.iitk.ac.in/student/gvaish
--------------------------------------
CERTIFIED EXPERT

Commented:
mgaurav,

Its good to see you back.

You have the following 4 questions that need your urgent attention.
Please take some time to close these questions.

EE userid mgaurav
Total questions asked 32 (100%)
Open questions 4 (12.50%)

Topic Area              URL              Date              
DB General http://www.experts-exchange.com/jsp/qShow.jsp?ta=dbgen&qid=20136587   06/16/01  
Java   http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20143995   06/30/01  
Java   http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20144337   07/02/01  
Java   http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20148484   07/10/01  

Your help will be highly appreciated.

Thanks,

maneshr
(NOT a moderator at EE)

Author

Commented:
mgaurav

I have checked the environment variables returned but USER_NAME or anything resembling it is not amongst them.

maneshr

I posted the question here in the hope that someone else has already done this and can give me the run down on how to acheive the required outcome. I think I'll leave the question here to see if someone can help, I might also post it at the apache area as well.

Cheers - Gavin
CERTIFIED EXPERT

Commented:
newmang,

".. posted the question here in the hope that someone else has already done this and can give me the run
                     down on how to acheive the required outcome. I think I'll leave the question here to see if someone
                     can help,..."

makes sense. Please remember to delete it after you have found the solution though.

Thanks :-)

Commented:
Almost similar Question posted:
http://www.experts-exchange.com/apache/Q.20272842.html

--- my response.
I think the ENV variable that you are looking for is REMOTE_USER

You might want to use:

$remote_user=$ENV{REMOTE_USER};


I am not sure whether you need to enable/load mod_setenvif module or not.  On my Apache, it is loaded.
 I try to comment it out (unload), the it still works.

It worth to check Apachedoc at
http://httpd.apache.org/docs/mod/mod_setenvif.html#SetEnvIf

THis code frag would let you view all the environment vars.

sub printenv {
 print "Content-type: text/html\n\n";
 print "<pre>";
 while (($key, $val) = each %ENV) {
         print "$key = $val\n";
 }
 print "</pre>";
}

give it a shot.

Author

Commented:
samri

Thanks for your reply, I was aware of the REMOTE_USER environment variable, my problem is that the variable is not being set for some reason. I have extracted and printed the entire environment passed to my application but this is not amongst them.

Cheers - Gavin

Author

Commented:
Thanks for your input, I worked out what I did wrong (a case of RTFM - you would think that after 30 years in I.T. I would know better!) - the problem was that although the webpage and form were protected by virtue of being in a protected directory the actual cgi script was not protected and this appears to be the problem.

Cheers - Gavin

Commented:
newmang,

That is very interesting.

-- my portion of funny stories, the authenticatin modules (LoadModule/AddModule) directives, in apache does work in order.  Cracking my head of why my Basic Authentication does not work, after loading mod_auth_nds.   Took me almost a week.  Discovered that you need to load the modules in the right order.

LoadModule nds_auth_module     modules/mod_auth_nds.so
LoadModule auth_module        modules/mod_auth.so
LoadModule anon_auth_module   modules/mod_auth_anon.so


-- off topic, but can relate to your stories.

Cheers.
Commented:
PAQed, with points refunded (100)

modulo
Community Support Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.