‘CGI’ Category

 

Understanding CGI programming

CGI Programming : Introduction for Beginners


CGI programming involves designing and writing programs that receive their starting commands from a Web page-usually, a Web page that uses an HTML form to initiate the CGI program.

The HTML form has become the method of choice for sending data across the Net because of the ease of setting up a user interface using the HTML Form and Input tags. With the HTML form, you can set up input windows, pull-down menus, checkboxes, radio buttons, and more with very little effort.
In addition, the data from all these data-entry methods is formatted automatically and sent for you when you use the HTML form.
CGI programs don’t have to be started by a Web page, however. They can be started as the result of a Server Side Include (SSI) execution command .”Using Server Side Include Commands”).
You even can start a CGI program from the command line. But a CGI program started from the command line probably will not act the way you expect or designed it to act. Why is that? Well, a CGI program runs under a unique environment. The WWW server that started your CGI program creates some special information for your CGI program, and it expects some special responses back from your CGI program.
Before your CGI program is initiated, the WWW server already has created a special processing environment for your CGI program in which to operate.

That environment includes translating all the incoming HTTP request headers . “. In addition to system information (such as the current date), the environment includes information about who is calling your CGI program, from where your program is being called, and possibly even state information to help you keep track of a single Web visitor’s actions. (State information is anything that keeps track of what your program did the last time it was called.)

Next, the server tries to determine what type of file or program it is calling because it must act differently based on the type of file it is accessing.
So, your WWW server first looks at the file extension to determine whether it needs to parse the file looking for SSI commands, execute the Perl interpreter to compile and interpret a Perl program, or just generate the correct HTTP response headers and return an HTML file.

After your server starts up your SSI or CGI program (or even HTML file), it expects a specific type of response from the SSI or CGI program. If your server is just returning an HTML file, it expects that file to be a text file with HTML tags and text in it.
If the server is returning an HTML file, the server is responsible for generating the required HTTP response headers, which tell the calling browser the status of the browser’s request for a Web page and what type of data the browser will be receiving, among other things.

The SSI file works almost like a regular HTML file. The only difference is that, with an SSI file, the server must look at each line in the file for special SSI commands. If it finds an SSI command, it tries to execute it.
The output from the executed SSI command is inserted into the returned HTML file, replacing the special HTML syntax for calling an SSI command. The output from the SSI command will appear within the HTML text just as if it were typed at the location of the SSI command. SSI commands can include other files, execute system commands, and perform many useful functions. The server uses the file extension of the requested Web page to determine whether it needs to parse a file for SSI commands. SSI files typically have the extension .shtml.
If the server identifies the file as an executable CGI program, it executes the program as appropriate. After the server executes your CGI program, your program normally responds with the minimum required HTTP response headers and then some HTML tags.

If your CGI program is returning HTML, it should output a response header of Content-Type: text/html. This gives the server enough information to generate any other required HTTP response headers.

After all that explanation, what is CGI programming? CGI programming is writing the programs that receive and translate data sent via the Internet to your WWW server. CGI programming is using that translated data and understanding how to send valid HTTP response headers and HTML tags back to your WWW client.

The big deal in all this is a brand new dynamic programming environment. All kinds of new commerce and applications are going to occur over the Internet. You can’t do this with just HTML. HTML by itself makes a nice window, but to do anything more than look pretty requires programming, and that programming must understand the CGI environment.

Finally, just why is it called gateway? Quite often, your program acts as a gateway or interface program between other, larger applications. CGI programs often are written in scripting languages such as Perl. Scripting languages really are not meant for large applications. You might create a program that translates and formats the data being sent to it from applications such as online catalogs, for example.
This translated data then is passed to some type of database program. The database program does the necessary operations on its database and returns the results to your CGI program. Your CGI program then can reformat the returned data as needed for the Internet and return it to the online catalog customer, thus acting as a gateway between the HTML catalog,
source credit : http://www.learnthat.com

 
 
 

CGI Scripts : Advantages and Disadvantages

CGI is a standard protocol for interfacing external application software with a Web server .
A CGI program is any program or application designed to accept and return data that conforms to the CGI specification.
CGI programs are the most common way for Web servers to interact dynamically with users. Many HTML pages that contain forms, for example, use a CGI program to process the form’s data once it’s submitted.
There are some of the advantages associated with CGI and certainly some drawbacks which are mentioned below :

Advantages of CGI Script
CGI programs supports good web browser compatibility as compared to other technologies .While main advantage you will notice with the CGI that it has no limitation of browser and firewall. It means CGI is language Independent .

-Perl is the language of choice for CGI development because of its string processing capabilities and cross-platform support.

-CGI is easy to learn and use. Infact ere are many commercial and freely available scripts that provide shopping carts, credit card processing, template systems, discussion forums, and so on.

-Cgi Doesn’t require any special library to create a CGI program, or write programs using a particular API.
-CGI supports many development languages, including those that can be compiled to executable code. This is important for companies that need to distribute software applications for the Web, but do not want to distribute their source code.

Disadvantage of CGI script


-CGI programs are slow since they need to fork a new process for every HTTP request and the database connection must be reopened for the next instance of the program, which is quite costly. It means greatest disadvantage of the CGI scripts is that they put excessive pressure or loads on the server. Programs which are poorly written create much problem.

 
 
 

Common Gateway Interface (CGI) : Introduction and Overview

Common Gateway Interface (CGI) a standard program for interfacing external application software with an information server, commonly a web server or program for transferring information between a World Wide Web server and a CGI program.

A CGI program is any program or application designed to accept and return data that conforms to the CGI specification. The program could be written in any programming language, including C, Perl, Java, or Visual Basic.
CGI programs are the most common way for Web servers to interact dynamically with users. Many HTML pages that contain forms, for example, use a CGI program to process the form’s data once it’s submitted.
Here information or data base server processes or responds to requests by returning output (in the case of web servers, requests from client web browsers).A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information.
if the request locates a file stored on disk, return the contents of that file;

if the request locates an executable command and possibly arguments, run the command and return its output
CGI defines how information about the server and the request is passed to the command in the form of arguments and environment variables, and how the command can pass back extra information about the output (such as the type) in the form of headers.

But flip side is that each time a CGI script is executed, a new process is started. For busy Web sites, this can slow down the server noticeably.

For Example Lets say you wanted to hook up Your linux database to the world wide web, thus to allow people to query . In this scenario you need to design a CGI application that web Daemon will execute to transfer information to data base engine and receives results back and display them to client , thus best example of gateway.

There really is no limit as to what you can hook up to the Web. The only thing you need to remember is that whatever your CGI program does, it should not take too long to process. Otherwise, the user will just be staring at their browser waiting for something to happen.

CGI program can be written in any language that allows it to be executed on the system, such as:

C/C++
Fortran
PERL
TCL
Any Unix shell
Visual Basic
AppleScript

The Concept of GET And POST


A Web Browser acts as client program , which access or retrieves data from different servers like FTP OR HTTP OR GOPHER. The Hyper text transfer protocol system is specifically designed for web service which consists of protocol ( rules to govern network)hat supports sending documents from the server to a browser, and that also support sending complex data from the client back to the server.
The most common methods are

GET — the data are passed within the query string of the URL. For example, accessing the URL

http://bla.bla.edu/stuff/program?query_string

sends the data included in query_string to the HTTP server running on the machine bla.bla.edu.

POST — the data are sent as a message body that follows the request message sent by the client to the server. This is more complex than GET, but allows for more complex data.