An alternative to this scheme is to specify a URL which is a program. When we point our web browser to such a program, it can do a wide variety of things -- in fact anything that the programmer who wrote it wanted it to do. The standard output stream from the program is sent to your web browser; thus, if you have a program which prints valid HTML code, you can generate dynamic information on the fly. Your program doesn't need to decide what to print until it receives a request, and then it can send back whatever it deems suitable.
If this communication was one way, that is if all you could tell the web server to do is to run a program, without providing it any additional information, this would probably be more or less just a curiousity. But this method of programming for the web does have a way of transmitting information from the browser to the webserver, and the protocol for doing it is known as CGI (Common Gateway Interface) programming. CGI refers to, among other things, the way that information can be extracted from, say, a fill-out form or drop down menu which is displayed in your browser.
Unlike some internet protocols, HTTP was designed to be extensible - you can even provide information that was not conceived of when the protocol was designed. It does this in a very simple way; when information is transmitted from a web server, it is preceded by a header, which explains to the browser the type of the content, the length, and just about anything else that anyone would like to communicate. Similarly, the web browser can inform the web server about what type of browser you're using, what types of content you'll accept, and other similar information, by constructing appropriate header lines. By using two newlines with no intervening characters as the termination of the headers, the protocol truly allows unlimited information to be transmitted. When you write a static web page, the web server takes care of providing the appropriate headers; when you are writing CGI programs, it becomes your responsibility. Fortunately for perl programmers, the CGI module not only takes care of details like the headers, it also allows you to create simple web pages without knowing anything about HTML, and more complex ones with only a small amount of HTML knowledge.
Before you write a perl program and place it on a webserver, you should realize that,
because of security reasons, CGI programs can only be executed from certain restricted
directories within the file system of the web server. If you just place a perl
program
in, say a public_html
location on a webserver, it will display as text, which
is rarely what you really want. So one of the first steps in CGI programming is to
either set up a personal web server, or to inquire from your local webmaster how to
gain access to a directory which is authorized to allow execution of programs. If
this is not possible, you can still develop CGI programs, using the CGI
module's offline mode (Section ).