CGI (Common Gateway Interface) is a standard Interface for WEB servers to provide information services. Through this Interface, WEB servers can execute programs, and return the information output by the program to the browser. Because data on the WEB is static, CGI programs can dynamically process viewer requests, such as saving user input information and returning relevant information based on user information. After the client sends a CGI request to the WEB server, the WEB server determines the data transmission method to the CGI program based on the CGI program type, generally, data is transmitted with CGI programs through standard input/output streams and environment variables.
CGI Input and Output principles
CGI Input/Output Method: CGI program uses standard input (STDIN) and standard output (STDOUT) for input and output. STDIN and STDOUT are two pre-defined file pointers. You can use the file read/write function to manipulate it.
In additionCGI programs also get input through environment variables, except that the environment variables provide some common information, this usually does not include the information you enter on the WEB page (except when using the GET method described below, you can check the environment variable QUERY_STRING to obtain the input data ), STDIN is usually used to transmit user input information. In general CGI program development, we need to care about the following environment variables:
In partEnvironment variables related to WEB servers:
- SERVER_NAME WEB server name
- SERVER_PORT WEB server listening address
- SERVER_PROTOCOL Protocol name and version used to send the request
- SERVER_SOFTWARE WEB server name and version
Part of the operation isCGI-related:
- REQUEST_METHOD Data transmission (Information Transmission) Method
- CONTENT_LENGTH Data Length
- QUERY_STRING