The purpose of this tutorial is to explain how to display dynamic web pages
on your browser, that is web pages that are the output of a (Perl, in this
tutorial) program.
The Perl language is one of the most commonly used language on the Web.
As a prerequisite, you should first study the Tutorial on the Perl language,
before studying CGI/Perl.
There are 2 ways to display a web page:
- the most common way is to provide the URL of a document written in HTML,
like: http://www.classleader.com/index.html
- another way is to provide the URL of a Perl program, using the extension
.pl (on windows) or .cgi (on Unix). In this case, the web server executes
the Perl program, and its output is then sent back to your browser which
displays it as a web page. The protocol used for this communication is
known as CGI (Common Gateway Interface)
In this first slide, we show how a cgi/perl program can be executed on
the server, to display a web page on your browser window.
1. OUR FIRST CGI/PERL PROGRAM EXAMPLE:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><head><title>A test</title></head>\n";
print "<body>The test was successful.</body></html>";
2. PROGRAM DESCRIPTION:
The first line is a reference to the PERL interpreter.
#!/usr/bin/perl
The second line describes the document format, and should include the keyword
"Content-type" followed by the type of document, followed by two linefeeds.
The third and fourth lines print the web page, in this case, an HTML document
with the words: "The test was successful".
3. PROGRAM EXECUTION:
Access the program by clicking on the following link:
A Simple Example
or, using your browser, type the following URL:
http://delphi.nova.edu/~jclevin/cgi-bin/CGI/prog01.cgi
4. SETTING UP YOUR OWN WEB SERVER
If you want to develop your own CGI scripts on your own server, you will need
to set-up your own web server (for example Apache or IIS), then download and
install the Perl programming environment (go to: http://www.perl.com).
|