What is a CGI

Source: Internet
Author: User
Tags data structures file url variables

CGI is a standard for how Web servers communicate with external programs, allowing external programs to generate HTML, images, or other content, and the server is handled in the same way as HTML, images, or other content generated by non-external programs. Therefore, the CGI program only allows you to generate content and dynamic content. The reason for using CGI is that it is a well-defined and widely supported standard, and it is not possible to implement dynamic Web pages without CGI, unless some of the special methods provided in some servers (and now other technologies other than CGI are becoming standard).

1. Definition:
CGI (Common Gateway Interface) is a tool for HTTP servers to "talk" to programs on your or other machines, and its programs must run on a network server.

2. Function:
The vast majority of CGI programs are used to interpret the input information from the form, and to produce the corresponding processing on the server, or the corresponding feedback to the browser. CGI programs make Web pages interactive.

3. Operating Environment:
CGI programs run on a server in a CERN or NCSA format on UNIX operating systems. CGI programs are also widely used on servers in other operating systems, such as Windows NT and Windows95, and they are also applicable to various types of machines.

4. CGI Processing steps:
⑴ sends user requests to the server over the Internet.
The ⑵ server receives the user request and gives it to the CGI program for processing.
The ⑶CGI program transmits the processing results to the server.
The ⑷ server sends the results back to the user.

5. CGI Server configuration:
The CGI program is not run on the server, and if you want to make it run smoothly on the server and handle the user's request accurately, you need to make the necessary settings for the server you are using.
Configuration: Depending on the type of server used and its settings, place the CGI program in a particular directory or with a specific extension.
⑴cren Format Server configuration:
Edit cren Format Server configuration file is usually/etc/httpd.conf/
Add in file: Exec cgi-bin/*/home/www/cgi-bin/*.exec
The first argument that appears in the command cgi-bin/* the name of the directory that appears in the URL, and indicates that it appears in the first directory after the system host, such as
http://edgar.stern.nyn.edu/cgi-bin/
The second parameter in the command represents the true path of the CGI program directory in the system. The CGI directory can be placed in the same directory as a network file, or in other directories of the system, but it must be guaranteed to have the same directory in your system. After the server is set up, you must restart the server (unless the HTTP server is started with inetd).
⑵NCSA Format Server configuration
is set on the NCSA format server in two ways:
① in srm.conf file (usually in the Conf directory):
Script alias/cgi-bin/cgi-bin/
The script alias command indicates that the files in a directory are executable programs that are used to execute these programs; The two parameters of this command are the same as the parameters of the EXEC command in the CERN format server.
② in srm.conf file add:
Add type application/x-httpd-cgi.cgi
This command indicates that a new file type has been added to the server, with the first argument being the MIME type of the CGI program. The second parameter is the file extension, which means that the file with this extension is a CGI program.
After you set up the server in one of the above methods, you must restart the server (unless the HTTP server is started with inetd).

The

6. CGI programming language
CGI can be written in any language, as long as the language has standard input, output, and environment variables. For beginners, it's best to use languages that are easy to archive and can effectively represent a large number of data structures, such as
UNIX environments:
perl (Practical extraction and reporting language)
Bourne Shed or TCL (Tool command Language)
Windows environment:
C and C + +
because most servers on the Internet use UNIX operating systems, And there are Bourne shells in almost any UNIX operating system, so most of the following examples are written with the Bourne Shell.

7. CGI Environment variables list
Use a good environment variable probe to view CGI environment variables
Server-name: Run the CGI sequence for the machine name or IP address.
Type of SEUVER-INTERFACE:WWW server, such as a CERN or NCSA type.
Server-protocol: Communication protocol, should be http/1.0.
SERVER-PORT:TCP port, generally the Web port is 80.
Http-accept:http the type of data that the browser defines to be acceptable.
Http-referer: Sends the form's file URL.
(Not all browsers transmit this variable)
Http-user-agent: Information about the browser that sent the form.
GETWAY-INTERFACE:CGI version of the program, under UNIX for cgi/1.1.
The actual path name contained in the Path-translated:path-info.
Path-info: Additional path when the browser sends data in Get mode.
The path name of the SCRIPT-NAME:CGI program.
Query-string: The data entered in the form, the content after the middle number of the URL.
Remote-nost: The host name of the sender, the value cannot be determined.
REMOTE-ADDR: The IP address of the machine that sent the program.
REMOTE-USBR: The name of the sender of the program.
Content-type:post sent, generally for applioation/xwww-form-urlencoded.
The number of bytes of data entered by the Content-length:post method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.