next up previous contents
Next: Data Tainting Up: Perl on the Web Previous: Introduction   Contents


Transmitting Information through CGI

We don't need to know any of the details of the way that CGI works, because the CGI module takes care of providing us with the information entered in forms or menus on web page, but some of the basics will be useful in understanding what CGI is all about. Information from a web page which is sent to a CGI program consists of one or more name/value pairs. One way of transmitting the name/value pairs to the web server is to append them to the URL of the CGI program, following a question mark, and being separated by ampersands. Thus, a request to a CGI program for a travel agency might look like:
http://www.travelagency.com/cgi-bin/find.pl?dest=Costa%20Rica&date=Jun%203
Notice that, to send a blank, the browser had to insert the sequence %20. There are a number of similar encodings which must be used to send characters which are not legal in URLs or filenames. Once again, the CGI module will spare us the need to worrry about these details. It's worth noting, however, that if you don't want to bother with filling out a form to pass information to your CGI program, referencing a URL constructed in this way will serve the same purpose, allowing a single CGI program to serve many different purposes. If you need to convert a string to its URL-encoded form, you can use the HTML::Entities module.

Variables sent to your program with this scheme are transferred in the environmental variable QUERY_STRING; you can examine $ENV{QUERY_STRING} for the gory details. Variables sent to your program using fill-in forms transmit that information through the headers, however. Thus, while it is certainly possible to get information from a CGI program without invoking special modules, most programmers prefer the convenience of using the CGI module, if for nothing else to retrieve parameters from encoded URLs and fill out forms using a common interface, and without having to confront the specific details of how the information is transmitted.


next up previous contents
Next: Data Tainting Up: Perl on the Web Previous: Introduction   Contents
Phil Spector 2002-10-18