Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?


by Hoot (Initiate)
on Oct 09, 2003 at 01:32 UTC ( #297785=perlquestion: print w/replies, xml ) Need Help??

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'.
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.
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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://297785]
Approved by barrd
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-12-02 07:20 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (17 votes). Check out past polls.