Click to See Complete Forum and Search --> : Can my Perl script see which .htaccess "user" is accessing it?


doctormelodious
04-02-2007, 11:29 PM
Greetings,

I have password-protected a directory, via .htaccess. (Actually my provider's control panel did that part behind the scenes.) Once a person has typed in their username and password to access the protected directory, the index.html page calls a Perl script which needs to know who is using it.

Is there any way the Perl script can see which .htaccess "user" requested the page that called it? Otherwise, I have to make the person log in twice: once to get into the directory, and another via log-in code I have to include in the script.

In my server logs, when there is a page request for a page that lives in a protected directory, it shows the "user" name in the output. But when I do a dump of $ENV variables using this code in a test script (called by a form on a page in the protected directory):

foreach (sort keys %ENV) {
print "$_ = $ENV{$_}\n\n";
}

the name of the user (in this case, me) is not in any of the variables. Is this because the script itself lives in cgi-bin, and not the password-protected directory?

Is there any way I can make the protected-directory log-in procedure do double duty?

Thanks!
DM

Jeff Mott
04-03-2007, 12:03 AM
Is there any way the Perl script can see which .htaccess "user" requested the page that called it?Yes. It will be available in $ENV{REMOTE_USER}.

the name of the user (in this case, me) is not in any of the variables. Is this because the script itself lives in cgi-bin, and not the password-protected directory?That's exactly right. So you will need to either password protect a directory within the cgi-bin or make a CGI-enabled directory within your protected directory.

doctormelodious
04-03-2007, 01:03 AM
Thanks for the reply Jeff!

DM