Prev NEXT

How CGI Scripting Works

Summary

In this quick tour of CGI scripting, we have seen that:

  • A CGI script is a program -- generally a C program or a PERL script.
  • On most servers, CGI scripts live in a directory named cgi-bin. The script is executed when the script's URL is requested by a browser.
  • Anything that the script sends to STDOUT will be sent to the browser. The string "Content-type: text/html\n\n" should be the first thing sent. After that, anything goes; but typically, valid HTML tags for a valid HTML document are sent.
  • Input is sent to the script by creating an HTML form whose ACTION specifies the script's URL.
  • When a script receives the data from the form, it has to parse out the different strings and convert all of the modified characters. We saw a simple C program that can perform these tasks. The CGI library for PERL (see the next page) makes the conversion easy for PERL scripts.

If you were doing this on a real Web site, you would typically store the results from each survey into a text file or a database so that you could look at the results later. That's easy to do from either a C program or a PERL script.

Advertisement

For more information, check out the links below.

Related HowStuffWorks Articles
More Great Links