On Sat, Mar 10, 2001 at 06:31:09PM -0500, Brad Rice wrote:
> I'm having a problem using CGI.pm on my webserver. I can run the script from
> the command line no problem, but when I try running it in the browser I get
> a 500 error message. This is the CGI.pm script:
> 

perldoc perlfaq9:

My CGI script runs from the command line but not the browser.   (500
Server Error)

    If you can demonstrate that you've read the following FAQs and that
    your problem isn't something simple that can be easily answered, you'll
    probably receive a courteous and useful reply to your question if you
    post it on comp.infosystems.www.authoring.cgi (if it's something to do
    with HTTP, HTML, or the CGI protocols).  Questions that appear to be Perl
    questions but are really CGI ones that are posted to comp.lang.perl.misc
    may not be so well received.
    
    The useful FAQs and related documents are:
    
        CGI FAQ
            http://www.webthing.com/tutorials/cgifaq.html
    
        Web FAQ
            http://www.boutell.com/faq/
    
        WWW Security FAQ
            http://www.w3.org/Security/Faq/
    
        HTTP Spec
            http://www.w3.org/pub/WWW/Protocols/HTTP/
    
        HTML Spec
            http://www.w3.org/TR/REC-html40/
            http://www.w3.org/pub/WWW/MarkUp/
    
        CGI Spec
            http://www.w3.org/CGI/
    
        CGI Security FAQ
            http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt


How can I get better error messages from a CGI program?

    Use the CGI::Carp module.  It replaces C<warn> and C<die>, plus the
    normal Carp modules C<carp>, C<croak>, and C<confess> functions with
    more verbose and safer versions.  It still sends them to the normal
    server error log.
    
        use CGI::Carp;
        warn "This is a complaint";
        die "But this one is serious";
    
    The following use of CGI::Carp also redirects errors to a file of your
    choice, placed in a BEGIN block to catch compile-time warnings as well:
    
        BEGIN {
            use CGI::Carp qw(carpout);
            open(LOG, ">>/var/local/cgi-logs/mycgi-log")
                or die "Unable to append to mycgi-log: $!\n";
            carpout(*LOG);
        }
    
    You can even arrange for fatal errors to go back to the client browser,
    which is nice for your own debugging, but might confuse the end user.
    
        use CGI::Carp qw(fatalsToBrowser);
        die "Bad error here";
    
    Even if the error happens before you get the HTTP header out, the module
    will try to take care of this to avoid the dreaded server 500 errors.
    Normal warnings still go out to the server error log (or wherever
    you've sent them with C<carpout>) with the application name and date
    stamp prepended.

Reply via email to