Web Perl   «Prev  Next»

Lesson 12The standard CGI variables
ObjectiveThe standard CGI variables and when they are available.

Standard CGI Variables

Learn what the standard CGI variables are and when and why they are avaible.
The standard CGI variables are listed here.
The individual variables are only defined when they have a useful value, so they will not all be available all of the time. In practice, you will only use the ones that you need. For example, the following CGI program displays the HTTP_USER_AGENT variable to tell the user what browser they are using:

#!/usr/bin/perl

$CRLF = "\x0d\x0a";
$browser = $ENV{"HTTP_USER_AGENT"};
$title = "What Browser?";

print "Content-type: text/html$CRLF$CRLF";

print <<BROWSER;
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>

<p>You are using $browser. 
</body>
</html>
BROWSER

Standard CGI - Exercise

Click the Exercise link below to write a program that displays the CGI variables.
Standard CGI - Exercise
In the next module, we will cover some specific Perl programming techniques that will help bring your ideas to life. Perl is an extremely powerful language, and it has some features that are particularly useful in Web programming.