Online Programz

Monthly Archives : September, 2009

Introduction To SGML

SGML stands for stands for standard generalized markup language. SGML is a meta language in which one can define markup language for documents.

Markup:

Markup language means a set of conventions used together for encoding texts. It must specify what effect is allowed, what is required and how style or effect is to be distinguished for text.

Need for SGML :

SGML was orginally designed to enable the sharing of machine readble documents in large products in Government legal and aerspace industry.

It is primarly used for text and database publishing.

Example :

Oxford English dictionary which was marked up completely in SGML.

SGML has no predefined tags of its own user can create tags of their own.

PERL

PERL stands for practical extension and Report language. It is one if the most widely usednlanguages for web programming today. PERL is commonly used because of its power, its flexiility and availability of preexisting scripts. It has powerful, text processing capabilitiesn and is arguably the most popular CGI scripting language.

Example program to print a line of text.

#!c:\.perl\bin\per1

#A first program in perl

print(”welcome to perl! \n”);

Thus program output is welcome to perl!

Here in the program #-> comment charactert to instruct the interpreter to ignore everything on the current line following #.

The file can be saved with extension .PL in the directory cgi.bin.

Basic Structure OF CGI

There are three steps in CGI processing,

  • Initialization
  • Processing
  • Termination.

Initialization :

Script determines the input, environment and state. Each time it acts like as it was invoked for the first time. The method of Invoking script can be determined using Request_Method variable.

The input can be retrieved using the following variables.

  1. If request method is GET, Query_STRING variable can be used to determine the input.
  2. If request method is POST, STDIN and CONTENT_LENGTH variable can be used to determine the input.

Processing:

Processing phase is further divided into 2 phases or steps.

Processing Input data:

Transform the data which differentates it from all other CGI programs.

Output the results:

Output is usually a header and some html in case of simple CGI scipts. More complex scripts, output graphics, graphics with text etc.

Termination :

  1. Termination refers to cleaning up resources after processing and quitting.
  2. All files, memory allocated must be freed or releases for other useful purpose. Failure to do this will report an error.
  3. An error exit routine can be used to check whether the script resources are cleaned up as thoroughly as possible.

Broad Steps Of CGI Process

  • Browser shows the document containing the form.
  • User enters the data into form and click submit button.
  • Script in browser will perform client side validation.
  • Browser decodes URL and contacts server.
  • Server translates the URL into a path and a file name.
  • Server realizes that URL point to a program.
  • Server prepares its environment variables and launch the scripts.
  • Script executes and reads environment variables and STDIN.
  • script sends appropriate MIME header to STDOUT for content.
  • Server send rest of its output to STDOUT and terminates.
  • Server will notify the termination of script and closes the connection to browser.
  • Browser displays the output from the script.

CGI normally resides in a directory called CGI-bin.

When a script is invoked by a server, the server passes the information to script via environment variables.

Common Gateway Interface And Its Working

CGI stands for common gateway interface. CGI is a set of standards by which web servers can communicate with external program to handle the data from the form. This is due to reason that web server is not programmed to process the form data.

CGI doesn’t communicate directly with browser. The browser talks with server, server in turn talk with CGI program and CGI returns the answer to server and server talks to the browser.

Working Of CGI :

A CGI is only a program which are generally called scripts because they were written in UNIX and shell script and PERL. PERL is a interpreted and immediately compiled into machine instructions.C language is also used, but it is not called as script normally.After looking at CGI program, server access information from browser.Before launching the scripts, it prepares a number of variables called environment variables representing the current state of server. If server is busy with various scripts, CGI excutes its scripts at once each with its own environment.