CGI is actually a section running on the server.ProgramThe general working principle is as follows: the user sends a request to the server, then the server calls this CGI program for corresponding processing, and then returns the processing result to the server, the server then sends the result to the user.
It is complicated to say, but it is not complicated to write the CGI program, because the server has redirected the input and output of the CGI program to the standard input and output, therefore, to write a CGI program, you only need to read the information from the standard input, and then send the processing result to the standard output. In this way, you can write the CGI program in any language that supports the standard input and output, however, the output content must meet the HTTP protocol.
The following is a CGI program written in shell to display time:
Vim shell_date.sh
Then, a CGI program with the same functionality is written in C language:
Vim c_date.c
The program output is as follows:
In this way, a simple CGI program for displaying time is completed.