Content area
Full Text
CGI programs permit the Web surfer to perform actions affecting the state of things on the Web server. In many cases, the Web server machine is also where the neat stuff lives, so that the CGI script has direct access to files, processes, and databases to fully respond to a request.
But sometimes the request needs to be shipped off from the machine that's supposed to handle the CGI query to a machine that can actually handle the query. For example, if you rent space on a virtual server to handle your customers' page-fetching activities, and also have CGI scripts to let them ask questions or order products, it's possible that the order-entry system actually lives at another machine not directly accessible to the CGI scripts. How do we let the CGI system access the order-entry system?
Well, one way is to let the CGI script perform the normal data-entry validation-retrying the form until the data is correct as far as can be determined without connecting with the order-entry system-and then bundle up a mail message to the order-entry system. This mail message contains all the parameters, so that the order-entry system can effectively "process the form," albeit remotely.
Now, there's nothing terribly tricky about this, until you start considering that form data might be tricky to flatten out into a mail message that survives one or more hops through potentially hostile mail systems. You could construct an ad-hoc encoding scheme in which each field's value is clearly delimited and protected so that odd characters (like embedded newlines or characters used for delimiters) don't trip up the system.
But there's an easier way. The standard CGI . pm module provides clean, complete, mail-safe encoding for all the parameters of a form, and easy methods to load and store that data. This means we can construct a form in the usual way with the CGI module and, when the time comes to execute the action remotely, just send mail. This mail includes the form, encoded by CGI's save routine, in the body of the message. At the receiving end, we'll use CGI . pm to decode the body of the message, and we instantly have access to the form elements with param, just as if the...