![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
What Is CGI, Anyway?Does Common Gateway Interface mean much, if anything, to you? Probably not. However, CGI really is the raison dêtre for this book. Without it, there would be no reason to talk about Perl and Web pages because there would be no way to link the two. CGI as a concept has been applied to many systems other than links between Web servers and application programs. For example, it would provide a clean and near-universal interface for database servers and their clients without the barriers introduced by proprietary systems. Software manufacturers sometimes seem to worry about making sure that you only do business with them, but a common gateway from one system to another provides a standard of sorts to which the manufacturers have to adhere; if they cant deal with it, no one will buy their applications. For now, anyone who actually knows what youre talking about when you bandy about terms such as CGI will assume that youre talking exclusively about World Wide Web applications. In that context, without the Web, there would be no CGI. And without the Internet, there would be no Web. CGI: The Force Behind the Web Where HTML gives the World Wide Web its look, CGI makes it functional. It is what its name implies: A common gateway between the Web server and applications that can be useful to the server, but doesnt run as a part of it. CGI is the only way the server can communicate with these other applications, such as a database.
A Common Gateway In technical terms, a gateway is an interface or an application that allows two systems to pass information between them. For example, Microsofts old Mail program and its newer Exchange are limited to sending mail only to other Microsoft Mail users. A separate product provides a Simple Mail Transfer Protocol (SMTP) Gateway so that mail can be sent to and received from the Internet. Likewise with your Web server. It doesnt know Perl from Adam, but through the mechanism of CGI it can handle requests from clients, or visitors to your site, and pass the results back. Because the server is only following a set of rules for passing information, it does not know or care what you use in the background to process what it sends you. The functions are totally independent of one another. Thus, you can write CGI programs in any programming language. The only requirement is that the information you send back has to be formatted in a way that the server recognizes.
The CGI Environment MS-DOS, UNIX and, to a limited extent, Windows users should be at least a little familiar with the concept of environment variables. For example, on both MS-DOS and UNIX, an environment variable called PATH stores the list of directories through which the operating system will search when you type a program name on the command line. To the operating system, whether its Windows or UNIX, the environment is a block of memory where variable names can be stored as string values, such as PATH=c:/bin;c:/usr/bin;c:/usr/local/bin. Taking this example further, whenever the user refers to %PATH% (on NT and 95) or $PATH (on UNIX), the operating system substitutes c:/bin;c:/usr/bin;c:/usr/local/bin. Programs can get into this block of memory, too. What makes this facility especially useful is that the environment is in global memory, which means that anything there is accessible by other programs running at the same time. The Web server fills in a standard list of environment variables when it runs; it fills in others when requests are made of it. Because the Web server runs all the time, anything it places in the environment can be read by another program, such as your Perl script, if the other program knows the names of the variables to read. In the simplest sense, this is how CGI gets information between the server and your program (see Figure 1.11). The details are a little more complicated, and youll learn about them in Skill 3.
CGI Programming LanguagesThis book deals with Perl as the preferred programming vehicle for CGI applications. However, as you have learned previously, the HTTP-CGI gateway has no requirements or preferences when it comes to the language in which a CGI application is written. Lets examine briefly the advantages and disadvantages of some of the most widely used languages. C, C++C, and more recently, C++, are the most popular languages for application and systems development. Figure 1.12 shows a snippet of code in C++.
Advantages These are some of the advantages of C and C++:
Disadvantages Some of the disadvantages of these two languages are:
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |