Hoot has asked for the wisdom of the Perl Monks concerning the following question:

I have the following:
#!/usr/bin/perl -w use strict; use diagnostics; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print header(), start_html("Address Book for \u$ENV{USER}"), h1("Use A +ddress Book");
What I want is the Title to read
"Address Book for Hoot"
but at the moment it is printing
"Address Book for - Netscape"

When I run the code from the command line it expands
$ENV{USER} and prints to the terminal:
"Address Book for Hoot"

Can someone tell me why it doesn't expand when called from the browser?

I am using RH9.0

perl -v: This is perl, v5.8.0 built for i386-linux-thread-multi (with 1 registered patch, see perl -V for more detail)

Replies are listed 'Best First'.
Re: CGI $ENV{USER}
by idsfa (Vicar) on Oct 09, 2003 at 02:00 UTC

    Because the %ENV for the CGI doesn't have a variable named USER. You need to remember that when you use a CGI, it is a program being run on the web server in the environment of that web server. It could be in Karachi, and certainly has no idea who "Hoot" is.

    A way to get closer to what you want would be to require the user to authenticate first, and then use $ENV{HTTP_USER}, which would be set to the login with which they validated.


    Remember, when you stare long into the abyss, you could have been home eating ice cream.
Re: CGI $ENV{USER}
by Roger (Parson) on Oct 09, 2003 at 01:58 UTC
    What's the uid of the webserver that is serving the CGI? I believe the $ENV{USER} is the user login that owns your webserver process.

    PS. On my apache 2.0 server on Windows, this variable is not even set. If you want to display the name of a remote user, you can use $ENV{REMOTE_ADDR} and $ENV{REMOTE_PORT} variables that are set by the web server.