NSW Schools


Server Scripts

Common Gateway Interface (CGI)

CGI stands for Common Gateway Interface. To permit interaction between a server and a browser servers support executable scripts. CGI stands for Common Gateway Interface. CGI provides a standard for interfacing external applications with information servers, such as HTTP or Web servers. A CGI program, is resident on the webserver as an executable script.

While the cgi standard ensures that all cgi scripts can be interpreted by all cgi compliant servers a script designed to run on one webserver that calls another program (such as an emailer or image map interpreter) will likely crash if installed on a webserver that does not support the component program being called by the cgi script. In this sence cgi scripts are platform dependent.

cgi scripts can be written in any of a number of both compiled and non-compiled languages that can be executed by the webserver on which the script is resident. Relevant languages include, C, Fortran, Visual Basic & AppleScript . If you use a programming language like C or Fortran, you know must compile the program before it will run. The distinction between compiled and non compiled programs is that (Source:

"An interpreted program, sometimes called a script, is a program whose instructions are actually a logically sequenced series of operating system commands, handled one at a time by a command interpreter. In turn, the command interpreter requests services from the operating system. The writer of the interpreted program need not be concerned by low-level storage management considerations. On the other hand, an interpreted program can not be as efficient as a compiled program, which has been processed by a language compiler. A language compiler converts source statements into something close to the strings of 0's and 1's that a processor ultimately is given to work on. Because this work is already done before a compiled program is run, it runs much more quickly.

An interpreted program in a language such as Perl is much easier to write than a program written for a compiler. Interpreted programs are ideal for small tasks and for "gluing together" a succession of compiled programs that are run from the interpreted program."

Perl CGI Scripts

Sample Scripts

Hello My Name Is

See the Hello My Name is CGI/PERL Script Run:

The code for this script is:
# prints a users name using a GET request!
print "Content-type: text/html\n\n";
print "Hello, world My Name is ";
print "$name";

The Mangler

Dr Lincoln Stein has installed "The Mangler" on the server of the Cold Spring Harbour Laboratory. The Mangler uses the Travesty algorithm to rearrange webpages.

Dr Stein has published the source code for this script:

Perl Script Syntax

Uploading & Executing Scripts

Further information on using Perl to write cgi scripts:

Inline Image - Go To