The Server Environment

In order to make HTTP communication possible, certain information about the server and the requester must be publicly available. The server saves such information in special variables--the environment variables.

Most of environment variables contain information about the server configuration, but a few also contain information about the source of a request:

HTTP_USER_AGENT
Identifies the browser
REMOTE_HOST
Indicates the domain name of the originating server.
REMOTE_ADDR
Indicates the IP address of the originating server.

Extracting these variables is easy, they are available to Perl as an ordinary hash.

#!/usr/local/bin/perl


$ua     = $ENV{'HTTP_USER_AGENT'};
$rhost  = $ENV{'REMOTE_HOST'};
$radd   = $ENV{'REMOTE_ADDR'};


print "Content-type: text/plain\n\n";


print "HTTP_USER_AGENT: " . $ua . "\n";
print "REMOTE_HOST: " . $rhost . "\n";
print "REMOTE_ADDR: " . $radd . "\n";