Write CGI programs with Delphi (4)
From this lecture, we will enter the CGI programming process. Through the a few of the previous studies, you have passed the basic knowledge of the CGI program. Now you can sit down and write the CGI program! Third, the CGI program design 1, the server side attachment (SSI) and gateways 2, the gateway: Other protocols in the Web Connection In the process of writing CGI programs, it is best to follow the key points of the following applications: (1) Propose Problem - - You have to solve the problem (2) Design phase - conceive the basic framework and function of the CGI program (3) Coding phase - implement ideology (4) Program Transplantation - Writing Portable Code (5) Leveling - Make the program more upstairs 1st floor 1, server-side accessory (SSI) and gateways will introduce server-side accessories SSI (Server Side Include) and gateways. Strictly said that SSI is not a CGI program design, but SSI can make a work that can be completed in a simple CGI program, and sometimes SSI is even the best choice. Therefore, it is a simple introduction here. SSI defines a set of commands embedded in HTML text. Before the HTML text is sent to the HTTP client, the web server will make the SSI command to pre-processes, and the processed HTML text is output to the HTTP client's browser. The SSI command format is: ssi commands are different from Java or JavaScript, which is handled on the server, not on the client, this is the CGI program is similar. Of course, in the functional range of SSI, its advantages are the same as the CGI program, and can increase the resources utilization rate of the server, and the HTML text containing SSI is available in any web browser in the client. The following is a commonly used SSI command: (1) include command (2) echo command (3) exec command (4) config command (5) fsize command (6) FlastMod Command The only supported parameter is file, this is Insert the file of the file specified by the file parameter in the current HTML text. If you understand the C language, you can see that the "#include" command in it and the C language can be the same.
For example, there are two html text: main.html and header.html, use include command in main.html: main.html: this is a title in header.html! h1> ( However, it seems that omnihttpd does not support the include command,: this document was last updated on html> When you use your browser to open main.shtml to see the last modified time. (To note, you must store main.shtml in the HTDOCS directory of Omnihttpd, and use the address http://localhost/main.shtml in the browser.) EXEC commands Two parameters are CGI and CMD. The former calls a license file, such as cgi = "/ cgi-bin / finger.cgi"; the latter calls a system command, such as cmd = "ls". Regret, OmniHTTPD does not support this SSI command (also the latest version of the current). Config Command Settings This command sets the server processing file and the method of displaying the date. It has two parameters: (1) Timefmt determines the format of the date. Use the Man StrfTime to query the available value in UNIX. (2) Sizefmt determines the format of the length of the document. The value is BYTES or AddRev. This command is not supported in Omnihttpd. Fsize Command This command shows the size of a given document. The parameter is file, specifying the path and document name of the document. FLASTMOD Command This command expresses the most close-up date of the specified document.
The parameter is file, specifying the path and document name of the document. 2, the gateway: through the Web Connection Other HTTP protocols, the HTTP protocol is not allowed to visit all resources of the Internet, and to visit the resources outside the HTTP protocol (such as POP3 and SMTP Removal Electronics), you need to go to the gate. The CGI program is a good method for real network. In many UNIX's HTTP server, some common network is provided, such as Finger, Wais, Archie, and more. But in Omnihttpd, this network is not available. But we can add network level to OmniHTTPD through the presence of the CGI program. The form and its processing HTML form is a part of the web document, which is used to fill the information filled with the user to the server. Tongmong, these information is delivered to the CGI program, and the CGI program is used to enter a series of operations or data to generate the HTML document that represents the handling results. From this, it can be seen that the key part of the CGI program is to obtain the input data and the HTML document, while the operation and data is divided into large numbers. Here, I will introduce how to get data and output HTML documents in Perl and Delphi.
First, we create a HTML document called Greeting.html: Greeting.html file (stored in the htdocs directory stored in Omnihttpd)