LIS 525 - CGI
CGI (Common Gateway Interface) scripts
are executed on the server
and can be written in a variety of languages.
The most popular language for CGI scripts is Perl.
A Unix/Linux shell script just contains Unix/Linux commands,
the same as can be typed when logged on.
An example of a shell CGI script
is as follows:
#!/bin/bash
#Lines starting with "#" are normally comments
#but the first line is also an instruction
#on where to find the shell program
#that will execute the script
echo Content-type: text/html
#The following (empty) line is necessary!
echo
echo '<html>'
echo '<body>'
echo 'It is now '
date
echo '</body>'
echo '</html>'
As you might guess,
the purpose of this particular script is just to display the date.
CGI on UWO Servers
Permission to run scripts
(including testing them with the Unix/Linux . command)
is generally denied on the main University servers.
Some executable CGI scripts have been set up by the the administrators,
however,
as the basis for allowing page creators access to certain functions,
including handling form data submission
and page redirection.
The FIMS SharePoint server (faculty.fims.uwo.ca)
simply treats CGI scripts as another file format.
Obtaining Scripts
Downloaded Scripts
If you download a script from a Web site,
it may be in compressed form.
In this case,
you will need to uncompress it.
At least some modifications are likely to be needed;
for example, the precise form of the following line
will depend on where the shell software is located on the server:
#!/bin/bash
Look for a "readme" file
and follow instructions.
Also look in the script itself
for instructions inserted as comments.
Writing Your Own Scripts
Remember that the script
already puts quotes around the HTML code.
So, if you want to use the script
to generate HTML code containing quotes,
you have to use the other kind of quotation marks;
for example,
echo "Jane Doe's Web site"
Ways Users Might Execute a CGI Script
- By typing in a URL.
- By following a link on a web page.
- By loading a page
that contains an image whose source is the script.
(This method is used sometimes, for example, for graphic counters.)
- From an HTML form with the ACTION attribute
set to the URL of the script.
- By loading a page
containing a Server Side Include
(for example
<!-#exec cmd="/cgi-bin/hello.cgi" ->)
For More Information
Home
Last updated October 19, 2007.
This page maintained by
Prof. Tim Craven
E-mail (text/plain only): craven@uwo.ca
Faculty of Information and
Media Studies
University of Western
Ontario,
London, Ontario
Canada, N6A 5B7