Vous êtes sur la page 1sur 4

CGI

The Common Gateway interface (CGI) is a method used by web server to run external
programs, known as CGI scripts, most often to generate web content dynamically.

CGI defines a standard way for web servers to run CGI scripts and to send their results
back to the server.

The job of the CGI script is to read the information that the browser has sent (via the
server) and to generate some form of valid response usually visible content.

Whenever a webpage queries a database, a CGI script is usually called upon to do the
work.
CGI programs can be written by any programming language.

To run the CGI scripts in Windows Operating System:


Install XAMPP.

What is XAMPP?

XAMPP is a free and open source cross-platform web server package, consisting mainly
of the Apache HTTP server, MYSQL database, and interpreters for scripts written in the
PHP (Hypertext Preprocessor) and Perl programming languages.

Program1:

#! "c:\xampp\perl\bin\perl.exe"
print "Content-type: text/html\n\n";
print "Hello, World!\n";

Store the program in c:\xampp\cgi-bin\cg1.pl

Execution:

http://localhost/cgi-bin/ cg1.pl
Program2:

#!"c:\xampp\perl\bin\perl.exe"
print "Content-type: text/html\n\n";
print "<html><head><title>Hello World</title></head>\n";
print "<body>\n";
print "<h2>Hello, World!</h2>\n";
print "</body></html>\n";

print "Content-type: text/html\n\n";

With this line, we're telling Perl to send the Content-type header to the browser. The
content type we're specifying is "text/html", which means the content is of type "text",
and subtype "HTML".

At the end of the line you'll notice the "\n\n". The characters "\n" tell Perl to print a
new line (like pressing the "Enter" key in a word processor). There should always be 2
newlines between the HTTP headers and the main content, which is why we print "\n\n"
after the header.

To know about
print "Content-type: text/html\n\n"
go to the link
http://www.httprevealer.com/usage_perl.htm

Program3:

#!"c:\xampp\perl\bin\perl.exe"
print "Content-type: text/html\n\n";
print <<END_HTML;
<html>
<head></head>
<body>Hello, World!</body>
</html>
END_HTML

The line, "print <<END_HTML", tells Perl to print out everything that
follows until it finds the line beginning with END_HTML. This is an
easy way to print out lots of lines at once.
CGI.pm

Some modules are included as part of the Perl distribution, these are called
standard library modules. Comprehensive Perl Archive Network (CPAN)
(http://search.cpan.org) consists of many modules that are not part of the
standard library.
The CGI.pm module is part of the standard library and it has been found in
Perl version 5.004.
CGI.pm has a number of useful functions and features for writing CGI
programs.

Program4
#!"c:\xampp\perl\bin\perl.exe"
use CGI qw(:standard);
print header,
start_html('Hello World'),
h1('CGI.pm is simple.'),
end_html;

use CGI qw(:standard);


we are using CGI module,

qw(:standard)means we are importing the “standard” set of


function from CGI.pm

Program 5:
#!"c:\xampp\perl\bin\perl.exe"
use CGI qw(:standard);
print header;
print start_html("Hello World");
print "<h2>Hello, World !</h2>\n";

print end_html;

Program 6
#!"c:\xampp\perl\bin\perl.exe"
use CGI qw(:standard);
print header;
print start_html(-title=>"Hello World", -bgcolor=>
"yellow", -text=>"red");
print "<h2>Hello, World !</h2>\n";
print end_html;
It contains Multiple Arguments :we have to specify the name of each argument with
-title=> , -bgcolor =>

Vous aimerez peut-être aussi