eXtropia: the open web technology company
Technology | Support | Tutorials | Development | About Us | Users | Contact Us
Resources
 ::   Tutorials
 ::   Presentations
Perl & CGI tutorials
 ::   Intro to Perl/CGI and HTML Forms
 ::   Intro to Windows Perl
 ::   Intro to Perl 5
 ::   Intro to Perl
 ::   Intro to Perl Taint mode
 ::   Sherlock Holmes and the Case of the Broken CGI Script
 ::   Writing COM Components in Perl

Java tutorials
 ::   Intro to Java
 ::   Cross Browser Java

Misc technical tutorials
 ::   Intro to The Web Application Development Environment
 ::   Introduction to XML
 ::   Intro to Web Design
 ::   Intro to Web Security
 ::   Databases for Web Developers
 ::   UNIX for Web Developers
 ::   Intro to Adobe Photoshop
 ::   Web Programming 101
 ::   Introduction to Microsoft DNA

Misc non-technical tutorials
 ::   Misc Technopreneurship Docs
 ::   What is a Webmaster?
 ::   What is the open source business model?
 ::   Technical writing
 ::   Small and mid-sized businesses on the Web

Offsite tutorials
 ::   ISAPI Perl Primer
 ::   Serving up web server basics
 ::   Introduction to Java (Parts 1 and 2) in Slovak

 

introduction to web programming
Environment Variables  
So, what do we have so far?

  1. First you write an HTML page with a FORM in it.

  2. Some user retrieves your HTML page using a web browser

  3. The web browser interprets the HTML and presents the Form to the user as a set of input widgets.

  4. The user inputs some data into the widgets and then clicks on a submit button

  5. The browser then goes through each of the input widgets and collects the information that the user has input and creates the body of the HTTP call it is going to send to the server referenced in the FORM ACTION attribute.

  6. Then the browser contacts the server using the method defined by the FORM tag's METHOD attribute and hands off the data.

So what does the server do with the data?

Typically, the server will hand the request off to some CGI script that has been specified in the ACTION attribute in the FORM tag that made the request

So the server must execute the CGI script and feed it the data received from the web browser.

To do so, the server creates an associative array that will be used to hold all of the data needed by the script. The array is called %ENV (You'll learn more about accessing and building associative arrays tomorrow).

A good deal of this information will be gleaned from the browser itself and a lot of it is really obscure junk that you will rarely use. However, for your reference, the following table outlines the Environment variables prepared by the server

Environment Variable Description
AUTH_TYPE Specifies the authentication method used to validate the user. This will only be set if the server is set to authenticate users.
CONTENT_LENGTH The number of bytes in the message body of the HTTP request. This is used by POST method request.
CONTENT_TYPE The media type of the incoming data.
GATEWAY_INTERFACE Specifies the protocol name and revision being used by the server to communicate with the script.
HTTP_ACCEPT Holds a comma delimited list of MIME types that the client will accept
HTTP_REFERER Specifies the address of the web page that posted the request
HTTP_USER_AGENT The name and version of the web browser used to make the request.
PATH_INFO Extra path information specified in the URL that called the script
PATH_TRANSLATED The server's real file system path to the script's location.
QUERY_STRING The URL-encoded data in a GET request
REMOTE_ADDR Specifies the IP address of the client's machine.
REMOTE_HOST Specifies the client's domain name.
REMOTE_IDENT Specifies the client machine's username if available.
REMOTE_USER Specifies the name used to authenticate the user if the user was authenticated using server-based authentication
REQUEST_METHOD Specifies if the request was GET or POST
SCRIPT_NAME Specifies the virtual name of the script. (The directory and filename)
SERVER_NAME The server's domain name
SERVER_PORT The port that the web server is running on
SERVER_PROTOCOL The name and revision of the protocol the server is using.
SERVER_SOFTWARE The name and revision level of the web server

As we said, most of this information will not be useful to your script.

In fact, for the most part, you will only want a few of these variables in your script.

If it is a GET request, your script will need QUERY_STRING.

If this is a POST request, the script will need CONTENT_LENGTH and will need to have the server send the body of the HTTP message to it as standard input.

But what does a CGI script look like? I do realize that this section went really fast and is pretty high level

Well that is because a lot of what you need to know will be discussed tomorrow. So let's stop here.

Previous | Next | Table of Contents