Chapter 6. The CGI Module
Introduction to GET and POST
The CGI Module, CGI.pm
Handling Forms
Handling Form Errors
Handling Fatal Errors
Handling Fatal Errors in the Browser
Quite often when a script doesn't work, you get a completely blank page in response. Even if you have included some useful "die" messages, you might still be looking at a blank page of output, with no clue provided as to what went wrong. The error message from your die statement was still generated, but it went to the server log instead of to the browser window.
If you are hosting on a virtual server somewhere, chances are good that you don't have access to this server log. This is unfortunate because the error messages that are stashed there can be of real help when you are trying to debug your script.
Fortunately, CGI.pm supports a method of redirecting error messages to the browser window as well as to the server log. This can be a real lifesaver if you don't have access to the error log and a nice timesaver even if you do.
To do this, you just have to invoke this behaviour when you use CGI.
Consider the script here.
Now try running the script here. See how the die message came out? An extra Content-Type line is printed, just in case none has been printed before. That extra line calling Carp is all it takes.
As a final example, you can
see how to customize the error message that gets displayed here.
Here's the script for it.
That concludes the introduction to the CGI module. It is a large module with many, many features. You are encouraged to look into the documentation if you want to get the most you can out of it.
Questions? Feedback?
Email me your
comments!
Like the course?
Please rate the site here
Copyright 2003-2007 Michael Gossland and
Associates. All rights reserved.
|