Posts Tagged ‘cgi’

Printing CGI Environment Variables

Monday, February 2nd, 2009

A Web/Application server interacts with CGI (Common Gateway Interface) scripts via environment variables. These variables are set by the server running the script and may be accessed (read only) by the script.  As noted, they are set every time a script is run. I have used the QUERY_STRING variable in the past to get the string that was passed to the script. I think of these as session variables that you can not create and/or update that contain server information.

I also have used the HTTP_REFERER to refer back to who called the script.


Env.pl

#!/usr/bin/perl print "Content-type: text/html\n\n"; foreach $key (sort keys(%ENV)) { print "$key = $ENV{$key}<p>"; }

Click here to see my web server variables
CGI Info: http://www.cs.unc.edu/Courses/jbs/lessons/www/arch/cgi/