in reply to A way to get the User in a variable from htpasswd?

After the person is logged in, this information should be in the %ENV hash. So, something like

my $username=$ENV{'REMOTE_USER'};

will generally provide you that information, assuming the user/agent is not broken.

Replies are listed 'Best First'.
Re: Re: A way to get the User in a variable from htpasswd?
by no_slogan (Deacon) on May 10, 2001 at 21:30 UTC
    Even better,
    use CGI; my $cgi = CGI->new(); my $username = $cgi->remote_user();

    Update: From CGI.pm:

    sub remote_user { return $ENV{'REMOTE_USER'}; }
    Heh, not a lot of difference in practice. But, hey, encouraging more people to use CGI is a good thing, right?
      Obviously every CGI program should 'use CGI', but why is it better to get the remote user out of the CGI query?

      Unless it's because of tainting... I know that %ENV is considered tainted until/unless you delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; Is the remote_user() that you get out of CGI automatically untainted?

        No, it isn't because of tainting because fairly recent CGI.pm defines:

        sub remote_user { return $ENV{'REMOTE_USER'}; }

        I advocate using CGI.pm's remote_user() because if, for example, a "broken" web server becomes popular that puts this information into $ENV{AUTHEN_USER} and not $ENV{REMOTE_USER}, then CGI.pm is likely to get updated to take this into consideration and you won't have to fix all of the places you used $ENV{REMOTE_USER} directly (nor waste time discovering the bug in your new server), etc.

                - tye (but my friends call me "Tye")