In the previous chapters, we completed a general discussion of CGI programs. Here, I give a simple demonstration program as a summary of the previous content.
To use this program, you need the latest beta version of OmniHTTPD: OmniHTTPD 2.0b1 (beta 1) for Windows 95/NT. If you don't have it, you can download it here (oh20b1.zip).
The method of installing OmniHTTPD is the same as in the first lecture, so I won’t go into it here. I will just talk about some setting issues in this version here:
Open the OmniHTTPD property settings dialog box, use the Web Server Global Setting button, go to the External page, and delete the .cgi settings. When not deleted, CGI programs with cgi as the extension are processed as Perl programs; in our course, the extension of the CGI program in the Perl language is .pl, and the extension of the compiled CGI program is .cgi. Therefore, the settings should be modified like this.
In this version of OmniHTTPD, the support for SSI (Server Side Include) commands is greatly enhanced compared to previous versions, and commands such as include and exec are supported. In the demo program, I used these commands.
After you download (ex8.zip), it contains three files: index.shtml, makelog.cpp and makelog.exe. index.shtml is a script containing SSI commands, please copy it to the c:httpdhtdocs directory; makelog.exe is a CGI program, please copy it to the c:httpdcgi-bin directory; makelog.cpp is the source file of makelog.exe, if If you want to modify the compilation, you must use a 32-bit compiler, such as VC, otherwise it cannot be used.
In addition, you need to make a modification to the settings in OmniHTTPD: select Default Virtual Setting and change Default Index to index.shtml on the Server page. In this way, when you type http://localhost in the browser, OmniHTTPD automatically loads index.shtml.
Create another WEB document and save it in the c:httpdhtdocs directory with the file name index.html. When you use a browser to access localhost, index.shtml first calls makelog.exe to store the user's access information, and then calls index.html to display it in the browser. The user's access information is stored in the userlog file in the c:httpdcgi-bin directory.
This example uses the basic environment variables and SSI technology in the CGI specification. Please study it carefully.
4. Database
Among CGI applications, database applications best reflect the powerful functions of CGI programs. There are many databases on the Internet, and the demand for WEB applications of these databases is also increasing (whether it is from companies or users). It can be said that the WEB itself is a huge database. How to effectively organize these huge data collections and publish them on the WEB is a topic that CGI and database systems jointly solve.
If you want to classify CGI and database applications, there are different classification methods from different perspectives. For example, according to the size of the database, it can be divided into text database, local database (Microsoft Access, etc.) and database server (MS SQL Server, Informix, etc.); according to the CGI processing content, it can be divided into front-end database CGI programs (with users using WEB browsers). Interactive CGI programs) and back-end database CGI programs (CGI programs that interact with the database), etc. Choosing the size of the database usually depends on the data volume and cost of the tasks you want to complete; whether to separate or combine the front-end and back-end when programming CGI programs usually depends on the complexity of your data processing.
Typically, if your data set is within a few megabytes, and there are no complex relationships between your data records, you can choose to use a text file to build the database, which can keep the cost to a minimum, and the text file has a database Advantages that the management system (DBMS, namely DataBase Management System) does not have: If an error occurs in your data, you can transfer your text file into any text editor for recovery, and if an error occurs in your database system, Unless you are a database expert, Otherwise it will be difficult to repair.
If your data collection is very large, or if your data records have complex relationships between them, it is best to use a database system. Using text files to implement a database of tens of megabytes would overwhelm any advanced RISC server. If you use a CGI program to handle complex relationships between data, it will inevitably increase the complexity of the CGI program and occupy too many server resources; on the other hand, using the functions of the database system can simplify the difficulty of CGI program design and improve development efficiency. .
When choosing a database system, you need to choose from the following aspects: 1. Operating system platform: You should choose the database system you are most familiar with, and you should also choose the operating system platform you are most familiar with. Only in this way can you avoid errors. mistake. 2. Price: You should choose the cheapest one among various database systems that can complete your work. Here, I can tell you about a free database system called MiniSQL. It must run on UNIX or linux platform. I I don't know where there is a free database system for the Windows platform. If anyone knows, please tell me and I will tell you in future courses.
Our course is about using Delphi to develop CGI programs, and Delphi provides the Interbase Server database system. Therefore, I will mainly talk about the development of CGI programs using the database system here. At the same time, since the database system reduces a lot of coding work, I combined the front-end CGI and the back-end CGI into one to complete user input processing and database operations in one CGI program. But on other system platforms, this method may not be used. Readers are asked to make their own decisions based on the previous discussion.
Here, I would like to explain several different CGIs and their differences in their use in our OmniHTTPD:
Standard CGI: Standard CGI must be placed in the directory set by /cgi-bin/ and can be modified at any time when OmniHTTPD is running.
Win CGI: CGI applied in Windows systems must be placed in the directory set by /cgi-win/. This CGI uses an INI file to obtain requests from the client browser, rather than using environment variables or standard input. We generally don't use this kind of CGI.
ISAPI: A CGI specification using dynamic link libraries proposed by Microsoft.
NSAPI: A CGI specification using dynamic link libraries proposed by Netscape.
Each of these CGI specifications has its own characteristics: Standard CGI can be written using executable programs or scripting languages such as Perl, but it is inefficient and takes up a lot of resources. Each CGI request will have an instance of the CGI program running in the server. Win CGI has the same features as Stardand CGI. ISAPI and NSAPI are highly efficient and resident in memory, and no matter how many CGI requests there are, there is only one instance running in the server. Only the data set corresponding to this instance is different; but this kind of CGI is not easy to debug because it must be on the WEB server. Updates are only available when the software is closed.
In the next lecture, I will give a demonstration program for White Page. White Page is a list of email addresses. You can allow users to query, edit, add, and delete this list through a WEB browser. In this lecture, the demonstration program I gave is only a query operation, and other operations will be described in subsequent courses.
This demonstration program is built on the Borland Interbase Server database and developed in Delphi. During development, I chose Standard CGI because it is easier to debug.
Our program is written using Stardand CGI, which can be easily debugged. After the debugging is successful, it can be easily changed to ISAPI/NSAPI in Delphi with just one statement (how about it, Delphi is very good!).