CGI PROGRAMMING
CGI PROGRAMMING
Introduction
1 CGI stands for Common Gateway
Interface
2 Script language
Unix shell script & perl
3 Interactive programming
APACHE DIRECTORY STRUCTURE
 CGI-BIN
 Conf
 Htdocs
 Icons
 Images
 logs
STRUCTURE OF CGI SCRIPT
 Two way of passing information
1.GET METHOD
2.POST METHOD
Environmental Variable
1: REQUEST METHOD
GET REQUEST METHOD
Introduction
Example: http://myserver.edu/cgi-bin/myprog.pl?
name=niloy&rollno=7312&age=24
Environmental Variable
QUERY_STRING.
POST REQUEST METHOD
Introduction
Standard Input
Format: var1=value1&var2=value2&……
Environmental Variable:
CONTENT_LENGTH.
URL ENCODING
For platform independence, all data passed to the server are
URL-encoded.
Some rules of encoding:::::
 Variables are separated by ‘&’.
 List of special character “+”, “()” “[]” etc
 Special character can escaped using two hexa decimal
Number
BASIC STRUCTURE OF CGI SCRIPT
Step 1: Initialization
 Check REQUEST_METHOD
 Parse string and extract variables depending
on “GET” or “POST”.
 Check CONTENT_TYPE, to find out if
the string is URL-encoded.
BASIC STRUCTURE OF CGI SCRIPT
Step 2: Processing
 Process the input data.
 Output the results (MIME-type header, and the
contents).
BASIC STRUCTURE OF CGI SCRIPT
Step 3: Termination
 Release the system resources.
 Terminate the program.
Cgi programming

Cgi programming

  • 1.
  • 2.
    CGI PROGRAMMING Introduction 1 CGIstands for Common Gateway Interface 2 Script language Unix shell script & perl 3 Interactive programming
  • 3.
    APACHE DIRECTORY STRUCTURE CGI-BIN  Conf  Htdocs  Icons  Images  logs
  • 4.
    STRUCTURE OF CGISCRIPT  Two way of passing information 1.GET METHOD 2.POST METHOD Environmental Variable 1: REQUEST METHOD
  • 5.
    GET REQUEST METHOD Introduction Example:http://myserver.edu/cgi-bin/myprog.pl? name=niloy&rollno=7312&age=24 Environmental Variable QUERY_STRING.
  • 6.
    POST REQUEST METHOD Introduction StandardInput Format: var1=value1&var2=value2&…… Environmental Variable: CONTENT_LENGTH.
  • 7.
    URL ENCODING For platformindependence, all data passed to the server are URL-encoded. Some rules of encoding:::::  Variables are separated by ‘&’.  List of special character “+”, “()” “[]” etc  Special character can escaped using two hexa decimal Number
  • 8.
    BASIC STRUCTURE OFCGI SCRIPT Step 1: Initialization  Check REQUEST_METHOD  Parse string and extract variables depending on “GET” or “POST”.  Check CONTENT_TYPE, to find out if the string is URL-encoded.
  • 9.
    BASIC STRUCTURE OFCGI SCRIPT Step 2: Processing  Process the input data.  Output the results (MIME-type header, and the contents).
  • 10.
    BASIC STRUCTURE OFCGI SCRIPT Step 3: Termination  Release the system resources.  Terminate the program.