CGI Scripts

Forms collect information from users by providing window-like controls on an HTML page. If you've ever signed up for a free email account or purchased anything online you've used a form to provide your name, address, phone number etc. to the web site you were visiting.

CIS 207 - HTML Forms vs. CIS 209 - Server-side Scriptings

In CIS 207 - Introduction to Web Development, we cover everything about creating the HTML and CSS to create forms. The actual processing takes place on the server, which we will cover in CIS 209 - Advanced Web Development. CIS 209 will cover classic ASP and PHP as it relates to processing form information from an HTML form and inserting it in to a database on the server and/or processing the information (login permissions, etc.).

Working with CGI Scripts

Although HTML supports tags that allow you to create forms, it does not have the ability to process that information. One way of processing information is to send it to a program running on the Web server, called a CGI script. A CGI (Common Gateway Interface) script is any program or set of commands running on the Web server that receives data from the Web page and then acts on that data to perform a certain task.

What is CGI?

CGI is not a language. It's a simple protocol that can be used to communicate between Web forms and your program. A CGI script can be written in any language that can read STDIN, write to STDOUT, and read environment variables, i.e. virtually any programming language, including C, Perl, or even shell scripting.

Structure of a CGI Script

Here's the typical sequence of steps for a CGI script:

  1. Read the user's form input.
  2. Do what you want with the data.
  3. Write the HTML response to STDOUT.

See CGI Made Really Easy at

By giving users access to programs that react to user input, the Web becomes a dynamic environment in which companies can interact with customers. Much better than users simply reading static web documents. CGI scripts make it possible for Web authors to:

  • maintain online databases containing customer information
  • publish catalogs for ordering and purchasing items online
  • publish databases containing product support information
  • determine the number of times a web page has been accessed
  • create server-side image maps
  • create message boards for online discussion forums
  • manage e-mail for discussion groups

Has anyone ever tracked a package online? UPS, USPS, FEDEX and many other companies offer online tracking of packages. You simply logon to their web site and punch in your tracking number, and instantly, you get current live data describing exactly where your package has gone since it left its destination. Once it arrives at its destination, you can even see who signed for it and exactly what time they received it. This is live data on the web!

When you signed our class guestbook to turn in the URL to your first web assignment, you filled out a form. When you clicked the SUBMIT button, your information was immediately added to the database. From that point forward, anyone that visited the guestbook and clicked on the VIEW button to view entries, got current information which included your newly added entry. This is live data on the web!

Since CGI scripts run on the Web server, you, as a Web page author, might not have the ability to create or edit them. In some cases, another programmer will create the scripts offered by the web server and provide you with their specifications, indicating what input the scripts expect and what output they create.

CGI scripts can be written in a variety of different computer languages:

Which language is used depends on the Web server. When you run a CGI script, you are actually running a program directly on the server. System administrators are often hesitant to grant access to the server due to the potential danger from computer hackers and the drain on system resources caused by large numbers of programs running simultaneously.

As we work through the Forms tutorial, we will not have access to CGI scripts on the Web server, so we'll just be working with the HTML end of the process.