What is CGI?

CGI" stands for "Common Gateway Interface." CGI is the method by which a web server can obtain data from (or send data to) databases, documents, and other programs, and present that data to viewers via the web. More simply, CGI is programming for the web. Any script can be called a CGI script as long as it's installed on the server end. However, the majority of CGI scripts are written in Perl (with C being the next most common). If you want to write your own CGI scripts, you'll need to learn Perl. It is exactly the fact that CGI is installed on the server end that makes it able to do all those amazing things such submit a form, create a guest book or forum, keep track of and rotate your ads etc.  The server has the capability to redirect data to any email address, persist data, dynamically serve out different content to the browser, among many other things that the browser alone simply cannot do.

Drawbacks?

One major drawback with CGI is that it launches a new program each time a user clicks on a form, so Web servers used for heavily trafficked sites could be running thousands of programs at once -- a huge drain on Web-site performance.

Specialized Programs

Users also complain about programs written for CGI that aren't reusable as Web sites change, because those programs are frequently very specialized. As a result, over the past several years, many large Web sites have phased out CGI in favor of application servers [Technology, April 12].  Like CGI programs, application servers accept user input and send back Web pages or other information. But an application server processes many users' input with a single program, dramatically improving performance.

Why Learn CGI?

If you're going to create web pages, then at some point you'll want to add a counter, a form to let visitors send you mail or place an order, or something similar. CGI enables you to do that and much more. From mail-forms and counter programs, to the most complex database scripts that generate entire websites on-the-fly, CGI programs deliver a broad spectrum of content on the web today. If you've ever looked at a site such as Amazon.com, DejaNews, or Yahoo, and wondered how they did it... the answer is CGI. CGI experience is also in high demand from employers now; you could substantially improve your salary and job prospects by learning CGI.

How CGI Works

1 User types data into a form on a Web site.

2 Data is transmitted back to Web server, which launches a new program

   to process the user's data. One new program runs for each user form.

3 The program processes data and may connect to other programs or

   databases on the server.

4 The program sends an existing Web page, a newly generated Web page,

   an image or other Web content back to the user's browser.

What is Perl?

Short for Practical Extraction and Report Language, Perl is a programming language developed by Larry Wall, especially designed for processing text. Because of its strong text processing abilities, Perl has become one of the most popular languages for writing CGI scripts. Perl is an interpretive language, which makes it easy to build and test simple programs.