Perl cgi ebook




















You will find it easier if you already have some basic programming experience, but the material covered can be mastered by anyone with just a text editor, some common sense and a computer.

If you want to learn how to program with Perl and then find out how far you can go with it, this is the book for you. An excellent companion on any programming course. Toggle navigation. About 5. By supporting dynamic content, CGI allows web servers to provide online applications that users from around the world on various platforms can all access via a standard client: a web browser.

It is difficult to enumerate all that CGI can do, because it does so much. If you perform a search on a web site, a CGI application is probably processing your information.

If you fill out a registration form on the Web, a CGI application is probably processing your information. If you make an online purchase, a CGI application is probably validating your credit card and logging the transaction. If you view a chart online that dynamically displays information graphically, chances are that a CGI application created that chart.

However, CGI remains the most popular way to do these tasks and more. CGI can do so much because it is so simple. CGI is a very lightweight interface; it is essentially the minimum that the web server needs to provide in order to allow external processes to create web pages. Typically, when a web server gets a request for a static web page, the web server finds the corresponding HTML file on its filesystem. So how does the whole interface work?

Web browsers request dynamic resources such as CGI scripts the same way they request any other resource on the Web: they send a message formatted according to the Hypertext Transport Protocol , or HTTP. If the web server recognizes that the request is for a CGI script, it executes the script. At its most basic, Example 1.

These variables contain information such as the identity of the remote host and user, the value of form elements submitted if any , etc. They also store the server name, the communication protocol, and the name of the software running the server. CGI scripts can either return their own output as a new document or provide a new URL to forward the request elsewhere. CGI scripts actually can return extra header lines if they choose, so to indicate that it has finished sending headers, a CGI script prints a blank line.

Finally, if it is outputting a document, it prints the contents of that document, too. The web server takes the output of the CGI script and adds its own HTTP headers before sending it back to the browser of the user who requested it. Example 1. The header contains the communication protocol, the date and time of the response, the server name and version, the last time the document was modified, an entity tag used for caching, the length of the response, and the media type of the document—in this case, a text document formatted with HTML.

However, note that nothing here indicates to the browser whether this response came from the contents of a static HTML file or whether it was generated dynamically by a CGI script. This is as it should be; the browser asked the web server for a resource, and it received a resource. This program, shown in Example 1. This program is quite simple. It contains only six commands, although the last one is many lines long. So if you do not know Perl well or if your Perl is a little rusty, you may want to have a Perl reference available to consult as you read this book.

The first line of the program looks like the top of most Perl scripts. You may not recognize the flags, however: the -wT flags tell Perl to turn on warnings and taint checking.

Warnings help locate subtle problems that may not generate syntax errors; enabling this is optional, but it is a very helpful feature. Taint checking should not be considered optional: unless you like living dangerously, you should enable this feature with all of your CGI scripts.

We will discuss taint checking more in Chapter 8. The command use strict tells Perl to enable strict rules for variables, subroutines, and references. Like warnings, it helps locate subtle mistakes, such as typos, that might not otherwise generate a syntax error. Furthermore, the strict pragma encourages good programming practices by forcing you to declare variables and reduce the number of global variables.

This produces code that is more maintainable. If you think you might migrate to either of these technologies in the future, you should begin using strict now. Now we start the real work. First, we set three variables. These are just a few environment variables available to CGI scripts. As we saw earlier, if a CGI script wants to return a new document, it must first output an HTTP header declaring the type of document it is returning.

It does this and prints an additional blank line to indicate that it has finished sending headers. It then prints the body of the document. It treats the text as if it were enclosed in double quotes, so the variables are evaluated, but double quotes do not need to be escaped.

We will see how to do this for the Apache web server a little later in Section 1. On Unix, the file system differentiates between files that are executable and those that are not. CGI scripts must be executable. Forgetting this step is a common problem. On other operating systems, you may have to enable other settings to enable scripts to run.

Refer to the documentation for your web server. As its title suggests, this book focuses on CGI programs written in Perl. Because Perl and CGI are so often used together, some people are unclear about the distinction. Perl is a programming language, and CGI is an interface that a program uses to handle requests from a web server.

Although CGI applications can be written in any almost any language, Perl and CGI scripting have become synonymous to many programmers. Perl is easy to learn because it resembles other popular languages such as C , because it is forgiving, and because when an error occurs it provides specific and detailed error messages to help you locate the problem quickly.

Perl allows rapid development because it is interpreted; the source code does not need to be compiled before execution. Perl contains extremely powerful string manipulation operators, with regular expression matching and substitution built right into the language. Perl does not require strict variable types; numbers, strings, and booleans are simply scalars. Perl interfaces with external applications very easily and provides its own filesystem functions. There are countless open source modules for Perl available on CPAN, ranging from modules for creating dynamic graphics to interfacing with Internet servers and database engines.

Furthermore, Perl is fast. When Perl reads a source file, it actually compiles the source into low-level opcodes and then executes them. You do not generally see compilation and execution in Perl as separate steps because they typically occur together: Perl launches, reads a source file, compiles it, runs it, and exits. This process is repeated each time a Perl script is executed, including each time a CGI script is executed.

Because Perl is so efficient, however, this process occurs fast enough to handle requests for all but the most heavily trafficked web sites. Note that this is considerably less efficient on Windows systems than on Unix systems because of the additional overhead that creating a new process on Windows entails. Several alternatives to CGI have appeared in recent years. Reading, Mass. Reviews User-contributed reviews Add a review and share your thoughts with other readers.

Be the first. Add a review and share your thoughts with other readers. C programmeertaal PERL. Protocollen informatica World wide web. Langage de programmation. Programming languages. All rights reserved. Please sign in to WorldCat Don't have an account? Remember me on this computer.

Cancel Forgot your password? Thomas Boutell. Web servers -- Computer programs. C Computer program language Perl Computer program language View all subjects.

Similar Items. Print version: Boutell, Thomas. Thomas Boutell Find more information about: Thomas Boutell. Electronic reproduction. Master and use copy. Digital Library Federation, December Each chapter ends with a Conclusion. World Wide Web Documents. The Universe of Web Documents. The CGI Standard. The Need for a Standard. The Goals of CGI. CGI Environment Variables. CGI Standard Output. CGI Standard Input. Obtaining CGI Access.

Creating Your Own Internet Site. Leveraging Existing Programs: cuptime. What Are Environment Variables? More Environment Variables. Handling User Input: Interacting with Forms.



0コメント

  • 1000 / 1000