0% found this document useful (0 votes)
42 views6 pages

2.cgi, Perl, PHP

The Common Gateway Interface (CGI) defines a standard for web servers to interface with applications on the server. CGI scripts are usually written in Perl and allow dynamic content generation by calling databases or other programs. CGI uses HTTP requests to pass data to scripts, with GET appending data to the URL and POST placing it in the request body.

Uploaded by

Jaspher Abong'o
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views6 pages

2.cgi, Perl, PHP

The Common Gateway Interface (CGI) defines a standard for web servers to interface with applications on the server. CGI scripts are usually written in Perl and allow dynamic content generation by calling databases or other programs. CGI uses HTTP requests to pass data to scripts, with GET appending data to the URL and POST placing it in the request body.

Uploaded by

Jaspher Abong'o
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

The Common Gateway Interface (CGI)

A standard for how a web server interact and transfer information to an application program (called CGI
script)
A standard for how a web server interact and transfer information to an application program (called CGI
script)
The Common Gateway Interface (CGI) defines a way for client programs (web browsers) to interface
indirectly with applications on the web server.
 CGI is a standard interface
 A CGI script (executable program) is usually executed to interact with it
 Can be written in any programming language
 CGI is responsible for generating dynamic content
 CGI can call remote databases
 Perl is commonly used to write CGI
 CGI (Common---Means application is supported by almost all web server and can be
used on all platforms, Gateway----Pathway between server and application programs,
Interface---Provides a well-defined way to call up its features)
Note: CGI is not a programming language
Other server side applications
a) Active server pages (ASP)
b) Java Servlets and Java Server Pages (JSP)
c) Python
d) PHP Hypertext Processor
The CGI process
 A user requests the HTTP web server and demands for the URL (Client open connection to
server using a URL)
 Client sends request to server known as HTTP request consisting of explicit data
 Server processes request – Server launches CGI program – CGI program runs – CGI
program outputs response
 Server sends response to client
 Client and server close connection
 Read explicit data (form data) and implicit data (status code and request headers)
 Generate results and send explicit data (data in the form of HTML file), and response
headers as implicit data.
Page | 2
 CGI program writes its output to the standard output stream
CGI Data
Data is (in general) collected at the user's browser using an HTML form (Remember form controls
and methods).
This data is submitted to the HTTP server as part of a normal HTTP request using either the GET or
POST methods.

HTTP is a request response protocol

Note: URL, a Uniform Resource Locator is a way of identifying the location of a file on the internet
HTTP GET: Messages sent to a server contain only a URL. Zero or more optional data parameters may
be appended to the end of the URL. The server processes the optional data portion of the URL, if
present, and returns the result (a web page or element of a web page) to the browser.
HTTP POST: Messages place any optional data parameters in the body of the request message rather
Page | 3
than adding them to the end of the URL.
HTTP HEAD: Requests work the same as GET requests. Instead of replying with the full contents of
the URL, the server sends back only the header information (contained inside the HTML section).

Perl (Practical Extraction Report Language)


 Most CGI scripts are written in Perl (Practical Extraction Report Language)
 It is an Open Source software
 It is stable,
 Perl Interface integration Supports Oracle, Sybase, Postgres, MySQL
 Works with HTML and XML
 Perl is extensible language
 Perl is an interpreted language
 Perl interpreter can be embedded into various other systems
 Used in web development
 Used to automate various tasks in Web servers
 Used in networking and bioinformatics
Check whether Perl is installed on your computer
You can execute the perl –v command on the command prompt to check if you have perl installed on
your computer on windows operating system
Install perl for Windows:
 Perl is based on the syntax and concepts from many languages such as C, Shell, Lisp, etc.
 A Perl program has a sequence of declarations and statements
 Loops, subroutines, and other control structures (;)
Steps to create this simple Perl program on Windows
 Open Notepad
 Save the file as hello.pl
 Execute the program by typing perl -w hello.pl
Elements of a Perl Program
Keywords
Instructions Perl recognizes and understand. Ex:
Page | 4
Print, Die, Return
Should not be re
Statements
Print: “hello world/n”
Blocks
Enclosed in braces
{ print “This is”;
print “a block”;
print “of statements”; }

Perl has 3 basic types of variables


1. Scalar
Holds a single type of value, preceded by a dollar sign
Can be a string, a number, or a reference
$foo = 1;
Types of value that can be assigned to a number :
• 12345 # integer
• -54321 # negative integer
• 12345.67 # floating point
• 6.02E23 # scientific notation
0xffff # hexadecimal
2- Arrays
• holds multiple values, preceded by the @ sign
@color ={ “red”, “blue”, “green”};
• Its index start at 0, print the first element of array
print “$color[0]\n”; // to print red
3- Hash
 Unordered collection of values
 Each value can be retrieved by its key
 Hash name is preceded by a % sign
 Declared by :
Hash Name -> Key -> Value
Page | 5
% pages =
( "fred", "http://www.cgi101.com/~fred/",
"beth", "http://www.cgi101.com/~beth/",
"john", “http://www.cgi101.com/~john/" );
Perl also contains:
 If … else statements
 If( expression) {execute this} else {execute this};
 More than four different types of loop
 While loop
 For loop
 Foreach loop
 Until loop
Control commands
 Last: terminates the execution of a loop
 Next: makes the loop go to its next iteration
 Redo: makes loop restart without evaluating loop conditions
Modifiers
 Allow any statement to loop based on some conditions
 Statements if expression
 Statements until/unless expression
 Statements while expression

#!/usr/local/bin/perl
print "Content-type: text/html","\n\n"; # NOTE: two newlines!!
#
print "<html>\n";
print "<head><title>It Worked</title></head>\n";
print "<body>";
print "<h1>It Worked</h1>\n";
print "If you can read this, it means I know how\n";
print "to get a CGI program working\n";
Page | 6
print "</body>\n";

Perl Example
#!/usr/local/bin/perl
#
# Program to do the obvious
#
print 'Hello world.'; # Print a message
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
PHP FORMS

You might also like