You are on page 1of 3

CGI

Common Gateway Interface (CGI) is a standard method used to generate dynamic content
on Web pages and Web applications. CGI, when implemented on a Web server, provides an
interface between the Web server and programs that generate the Web content.

When you are dealing with Web pages, you will often hear people talk about CGI or CGI
scripts without ever explaining exactly what that is. Essentially, CGI is the connection (or
interface) between a form on a Web page and the Web server.

Web pages cannot interact directly with the reader. In fact, until JavaScript came along, Web
pages had no way of interpreting reader reaction except through interaction with the server
they were running on. This interaction is done through scripts and programs that use common
gateway interface to create interactive programs on your Web pages.

Some Things to Remember About CGI

1. CGI is not the program itself


CGI is simply the interface between the Web page or browser and the Web server that
runs the program.
2. You must have CGI access to run programs on your Web page
Many of the less expensive and free hosting providers do not allow CGI access on
their servers. Contact your hosting provider for more information.
3. Any program or script that will run on your Web server, can be used as a CGI
program
Most people use Perl to write their CGI scripts, but other languages include C and
C++, Tcl, and UNIX shell scripts.

Uses of CGI Scripts

Some of the most interesting uses of CGI are to create Web documents that depend on user
interaction. There are scripts to take readers to random pages on the site, create pages specific
to them based on form input, and generate pages based on databases of information.

CGI scripts are used to resolve form data, put that data in to databases, send the data out as an
email message, respond to the form entry with email or another Web page, and much more.

CGI scripts also are used for behind the scenes interaction with Web readers. They
can set and read cookies, get and tabulate information such as browser and
operating system, calculate hit counts, and monitor Web traffic. Why Use CGI?

Many of the uses of CGI can be duplicated by newer technology such as JavaScript and
ActiveX. The primary benefit to using CGI rather than browser based scripting is that you
can be sure that all of your readers (with very few exceptions) will be able to use the
program. Java, JavaScript, and ActiveX can all be turned off within the browser, and many
browsers simply don't support them. Also, it is becoming more common for company
firewalls to disallow these technologies to work in their system (often for security or
bandwidth reasons). Because CGI scripts are run on the external Web server, they are not
limited by browser or firewall limitations.
Why Not Use CGI?

The biggest drawback to CGI Scripts is that they can put a lot of load on a Web server.
Poorly written programs can fall into endless loops tying up server processor time. The Web
browser will time out (usually after around 5 minutes), but often the server will continue to
run the program until a system administrator comes in and shuts off the faulty script. The
browser based scripting tools mentioned above have the advantage of running off the reader's
computer. They use the processor locally rather than on the Web server itself, and so are less
intense on the Web server.

You might also like