Professional Documents
Culture Documents
Client CGI S E R V E R 1 2
Client CGI S E R V E R 1 2
INTRODUCTION:
S
E
CLIENT R CGI
1 2
V
E
R
3
4
Steps
CGI 1
2.WHAT ARE CGI SCRIPTS?
CGI scripts are external programs that run on the Web server. CGI
scripts are used to create highly interactive Web publications. The standard
that defines how external programs are used on Web servers and how they
interact with other applications is the Common Gateway Interface. The three
keywords that comprise the name of the standard---common, gateway and
interface---describe how the standard works.
CGI scripts are also called gateway scripts. One can write
gateway scripts in almost any computer languages that produce an
executable file. The most common language for scripts is the following:
CGI 2
Bourne Shell
C Shell
C/C++ Shell
PERL
Python
Tcl
Visual Basic
CGI 3
*Process input, typically search strings, and output a document
containing the results of the search.
*Validate user identification and password information and
grant readers access to restricted areas of the Web site.
*Process input from image maps and direct the reader to
associated documents.
*Add the reader’s feedback or survey responses to a database or
index.
*Track visitors to Web pages and post continually updated
numbers to the Web pages as it is accessed.
*Generate documents based on the type of browser the reader is
using.
*Perform post-submission processing and output results for the
reader.
CGI 4
the format of an HTTP header followed by a blank line. The blank line
separates the header from the data passing back to the browser. Output
containing Location and Status directives usually consists of a single line
because the directive contained on the Location or Status line is all that
server, and when there is no subsequent date, no need to insert a blank line.
The server interprets the output, sets environment variables, and passes the
output to the client.
CGI 5
6.INPUT TO CGI SCRIPTS:
Environment variables:
Variable Purpose
CGI 6
HTTP_ACCEPT Indicates the MIME type content types the
browser will accept, as passed to the
gateway script via the server.
CGI 7
SERVER_PORT Identifies the port number the server
received the request on.
Sending data as standard input is the most direct way to send data.
The server opens the standard input stream and reads the specified amount
of data.
CGI INPUT:
The HTTP POST method uses the standard input streams. When
Receives data by the standard input stream, the server assigns the value with
the length of the input stream to the CONTENT_LENGTH variable.
CGI 8
7.CGI SCRIPT STRUCTURE:
INITIALIZATION:
State information will come from the input rather than the
operating environment or static variables. Each time CGI scripts are
invoked, it’s as if they’ve never been invoked before. Every thing must be
initialized from scratch.
PROCESSING:
CGI 9
OUTPUT:
TERMINATION:
After the script finishes processing the input, the script should
return output to the server. The server will then return the output to the
client. Generally, a blank line and a body in the form of HTTP response that
includes a header follow this output. Although the CGI header output is
strictly formatted, the body of the output is formatted in the manner you
specify in the header. For example the body can contain an HTML document
for the client display.
CGI HEADERS:
1.content-type
2.location
3.status
CGI 10
A single header can contain one or all of the server directives,
your CGI script outputs these directives to the server. Although the header is
followed by blank line that separates the header from the body, the output
does not have to contain a body.
The status field passes a status line to the server for forwarding
to the client. The status code shows the general status as follows:
Although servers use many status codes, the status codes you pass to a
client via your CGI script are usually client error codes.
Basic hello world CGI script in C, with basic HTML output added
CGI 11
int main (int arc, char *arc[])
{
printf (“Content-type: text/html\n\n”);
printf (“<html>”);
printf (“<head>”);
printf (“<title>Hello, world!<title>\n”);
printf (“</head>”);
printf (“<body bgcolor=\”#FFFFFF\”>\n”);
printf(“<center><h1><Hello, World!<h1><center>\n”);
printf(“<body>\n”);
printf(“<html>\n”);
return(0);
}
Platform Independence:
CGI 12
maintenance, and the capability to perform the chosen task should also be
considered.
Server Independence:
CGI 13
10.CONCLUSION
The Common Gateway Interface opens the door for adding
advanced features to your Web publications. This workhorse running
quietly in the background less you use fill-out forms, database queries,
and index searches and create documents on the fly. You use CGI
whenever you want to open a two-way communication channel with
the reader. CGI enhancement to Web means extra for Web publishes.
Still, the payoff associated with CGI makes the extra effort truly
worthwhile.
CGI 14