page content: What is CGI and What Does CGI Stand For, overview of how CGI works and example of commen CGI scripts. CGI vs. Dynamic HTML

What is CGI and What Does CGI Stand For

The Common Gateway Interface (CGI) allows the site owner to define a special response to specific requests from clients, usually visitors to the site.

When someone visits your site through a web-browser or a similar program, his computer (the client) and the site's computer (the server) exchange data according to some global protocol, usually <HTTP>. During this process, the client asks for a certain resource—a web page, a file, etc.—and the server needs to decide how to answer this request. Here CGI can come into play.

How CGI works

CGI scripts and applications sit in your site's <cgi-bin directory>, and can be accessed like ordinary <URLs>. For example, if you have a script called process-form.pl, you can activate it by pointing your browser to www.your-site-name.com/cgi-bin/process-form.pl . Entering this URL is the equivalent of finding a program on your computer and clicking to activate it.

However, if CGI scripts were deaf and blind to your changing visitors, they would do little good. Suppose the purpose of your process-form.pl script is to add a new user to your database. The script needs to know the user's details, like name, email address, etc.. This can be done in two methods: appending these parameters to the URL (called GET), or sending them "behind the scenes" (called POST).

In the former method (GET), the URL may look like this:

/cgi-bin/process-form.pl?name=jonny&email=jonny@mail.com

Where the words highlighted in green are the parameter names, and the words in blue are the values. If the pl script is expecting these two parameters, it can access their values and add the new user to the database.

CGI scripts

In the above example, the extension of the script name (.pl) suggests this script is written in Perl. But CGI scripts can be written in any language, from C to shell scripts. They can be un-compiled script files (i.e. simple files containing the code in text format), or compiled ones (i.e. application files with .exe extension, where the source code is inaccessible).

There are many CGI scripts offered throughout the Internet, from the most basic <stat counters> to complete <shopping cart> solutions. When hunting for scripts, be wary of their source: scripts running from your cgi-bin directory have substantial purview over your site.

Keep in mind that with classic CGI, every CGI call opens a new thread on the server, which might overload it and cause it to crash. Newer methods, like SCGI (Simple CGI) and FastCGI address this issue and improve performance.

CGI vs. Dynamic HTML

Don't confuse the two. CGI can be used to generate dynamic HTML, but it's not the only option, and certainly not the preferred one. You can use <PHP>, <ASP>, Perl, etc. to create dynamic pages outside your cgi-bin directory, usually without the performance overhead of CGI.

 

***SOCIALIZEIT***