|
Overview
If you don't have any form of error trapping in your scripts any errors will redirect you to the
Spaceports main page. This can be very confusing when trying to find the cause(s) of the
problem.
Fortunately, there is something you can do to make bug tracking a little easier - tell Perl to
print error messages. I will show you two possible ways of doing that here.
Errors to browser
By inserting the following code in the second line of your scripts any internal errors will be
printed to the browser window in the form of an error message. Do not put anything before the
line defining the path to Perl.
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
If you still get redirected to the Spaceports page, then the problem can be (at least) one of
four things:-
- Incorrect path to Perl
- Incorrect file permissions
- Incorrect format when uploading
- Incorrect filename or path when calling the script
Errors to a log
This one is a little more complicated, but it will allow you to have a text error log file for
reference. The main advantage is that it will log any errors that occur when your visitors
try to access your scripts if you leave it in there after debugging.
- Connect to the CGI-BIN server via FTP
- Go to the
public_html directory
- Create a directory called
errors
- CHMOD
errors to 777
- Create an empty text file called
errorlog.txt
- Upload it to the
errors directory
- CHMOD
errorlog.txt to 777
Now, start all your scripts with the following code (replacing username with your
username):-
#!/usr/bin/perl
BEGIN
{
use CGI::Carp qw(carpout);
my $errorlog = "/home/username/public_html/errors/errorlog.txt";
open(LOG, ">$errorlog") or die("Unable to open $errorlog: $!\n");
print LOG "Errors:\n";
carpout(*LOG);
}
Users who signed up for their CGI-BIN account after end July 2000 but before the middle of
February 2002 will need to replace home with home2 in the code above.
Users who received their CGI-BIN account after the middle of February 2002 will need to replace
home with home3 instead.
You will then be able to see your stored error messages by going to:-
http://cgi-bin.spaceports.com/~username/errors/errorlog.txt
If you are feeling a little more adventurous, you could use a separate log file for each script
you use. Remember there is a 1000 file limit on the CGI-BIN server though.
|