9.4 CGI Environment Variables
Most of the information needed by CGI programs is made available
via Unix environment variables. Programs can access this information
as they would any environment variable (via the Here's a simple Perl CGI script that uses environment variables to display various information about the server: The preceding program outputs five environments as an HTML document. In Perl, you can access the environment variables with the#!/usr/local/bin/perl print << EOF Content-type: text/html <HTML> <HEAD><TITLE>About this Server</TITLE></HEAD> <BODY><H1>About this Server</H1> <HR><PRE> Server Name: $ENV{'SERVER_NAME'}<BR> Running on Port: $ENV{'SERVER_PORT'}<BR> Server Software: $ENV{'SERVER_SOFTWARE'}<BR> Server Protocol: $ENV{'SERVER_PROTOCOL'}<BR> CGI Revision: $ENV{'GATEWAY_INTERFACE'}<BR> <HR></PRE> </BODY></HTML>
%ENV
hash.
Here's typical output of the program:
<HTML> <HEAD><TITLE>About this Server</TITLE></HEAD> <BODY><H1>About this Server</H1> <HR><PRE> Server Name: www.whatever.com Running on Port: 80 Server Software: NCSA/1.4.2 Server Protocol: HTTP/1.0 CGI Revision: CGI/1.1 <HR></PRE> </BODY></HTML> Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|