Forum Moderators: coopster & phranque

Message Too Old, No Replies

Command to get $AUTH_USER in password-protected Perl file?

Simply need command & syntax to accomplish this

         

MultiMan

8:40 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



Here's a quick request for anyone who knows the answer offhand. I am sure it's simple, but it seems to be evading me, so I thought I'd ask here instead of spending any more wasted time.

In a .cgi file (PERL), located inside a password protected directory, I need to capture
$auth_user
$auth_pw
$ip

That is, a user has already logged-in using .htaccess authentication on a UNIX server. So, their auth info is already set when they reach this .cgi file.

If I was trying to accomplish this in a PHP file, the equivalent would simply be coded as:
$auth_user = $PHP_AUTH_USER;
$auth_pw = $PHP_AUTH_PW;
$ip = $REMOTE_ADDR;

But I am not using PHP in this situation.

Does anyone know offhand what the calls (and exact syntax) would to perform the same feat in a PERL instead?

Thanks in advance.

upside

1:11 am on Sep 29, 2004 (gmt 0)

10+ Year Member



You will need to see which environmental variables your particular server supports. Assuming that you are using Apache basic authentication, the following should work:

$auth_user = $ENV{'REMOTE_USER'};
$auth_pw = $ENV{'REMOTE_PASSWD'};
$ip = $ENV{'REMOTE_ADDR'};

MultiMan

1:17 am on Sep 30, 2004 (gmt 0)

10+ Year Member



Thanks!

Except for the password one, your code did the trick. (I don't know why only the password code did not work, though.)

The server info is:
Apache 1.3.31 (Unix)
Perl Version 5.6.1

When a user logs in to that password-protected directory, the .htaccess calls a .htpasswd file from off the web (parallel to /public_html/). In that offweb text-file (.htpasswd) the passwords are crypted when created (by another perl file).

But since my new perl file is only seek to retrieve the info from the logged-in user's browser, I would not think it matters.

Anyway, I appreciate your help. Thanks again.