Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryTutorials and Answers

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

How CGI Works

When you understand this article, you will have

  • an intuitive understanding of what CGI is,

  • a better grasp of what is possible and what is not, and

  • more confidence when installing CGI programs.

You already understand that when you surf the internet your browser retrieves (or gets served) information from other computers.

Those other computers send (or serve) information to your browser with special computer software called a server. Every computer that serves information to internet browsers uses server software.

Your browser asks the server software for something and the server software gets it for you.

You can compare it to a restaurant. You give your order to the server (the wait person) and the server gets it for you.

Just as you always have to go through the restaurant's server person to get food, so your browser always has to go through a server program to get information.

Most restaurants have food ready to be served immediately, such as drinks and snacks, and also have food that requires the skills of a cook to prepare before serving.

Most remote computers on the internet have information ready to be served immediately, such as web pages and images, and also have information that requires processing before serving.

When you want a custom prepared meal, you order it through your server person. The server takes it to another person. This person is called a "cook." The cook prepares the meal by gathering together the appropriate ingredients and combining them correctly; then gives it to your server. Your server delivers the meal to you.

When your browser wants custom information, the browser tells the remote computer's server software. The server hands it to another program on that computer. That program is called a "CGI program". The CGI program gathers together the appropriate data and does any required calculations on it; then gives it to the server. The server delivers the information to your browser.

The custom prepared meals you can get at a restaurant are limited to the kitchen equipment at hand, the skills of the cook, and the available ingredients.

The custom information you can get with your browser is limited to the the operating system of the remote computer, the type and quality of CGI programs on the computer, and the available data.

The servers at a restaurant have a specific method of sending requests to the cooks and receiving meals from the cooks. That method could be called the server/cook interface; it is a common gateway through which requests are made and meals received.

The server software on a remote computer has to follow a specific method (called a "protocol") to send requests to CGI programs and receive custom information back. That protocol is a server/program interface. It is a common software gateway through which requests are made and custom information received. It is called "Common Gateway Interface" or "CGI".

Let's suppose you order a meal in a restaurant and the server person sends your order to a cook. The meal is taking a long time and you have another appointment. So you leave the restaurant before your meal arrives.

The server person at the restaurant notices you're gone and tells the cook. So the cook stops cooking your meal -- no sense putting any more effort into it when you're not there to receive your order.

Let's suppose you're at a web page and click a link. The remote computer's server software sends the request to a CGI program for fulfillment. It's taking a long time and you're in a hurry. So you leave the site and go surf somewhere else.

The server software on the remote computer notices your browser is gone and tells the CGI program. The CGI program quits running -- no sense using computer resources when you're not there to receive the information.

That's how CGI works.

Computer programs are CGI programs only when they communicate with the server using the CGI protocol.

Computer programs (including CGI programs) can be written with any programming language that the computer's operating system can understand. Perl is currently the most popular programming language used for CGI programs, but it is definitely not the only one so used.

The limitations of CGI are limited only by the browser you're using, the remote computer's limitations, and the programs the remote computer has on board.

So, how about a real-world example?

One of the most broadly useful CGI scripts is one that processes data from a feedback/contact web page form.

For an example we will use our own Master Form V4

A web page is in your browser. The page contains a form.

You fill in the form and click the submit button.

The browser copies the information you provided on the form, along with the name of the CGI program that will process the information (in this case Master Form V4).

The browser sends the information to the remote computer's server. (Your browser doesn't make decisions about what to do with the information. Everything just gets sent to the server. The server then makes the decisions.)

The server looks at the information your browser sent and decides what to do with it. In this case, it makes the information available to Master Form V4.

In between the time when your browser sends the information to the server and the time it hears back from the server, Master Form V4 :

  1. Accepts the information from the server.

  2. Mails the form contents to the appropriate email address.

  3. Gives the server the URL of a "thank you" page.

The server accepts the URL from Master Form V4 and gives it to your browser. Your browser goes to that URL -- which means the next page you see is a "thank you" page.

That's the complete CGI cycle :)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC