Solved

Internal Server Error (500)

Posted on 1999-01-15
4
181 Views
Last Modified: 2013-12-25
It's probably pretty simple, but I can't ever get my scripts to work.  I EXACTLY COPIED a sample script, ran dos2unix on it, chmoded to 755, and ran 'perl -w' and got no errors.  Why am I getting a 500 error, and why do I get a 500 error every time?


#!/usr/local/bin/perl
$mail_prog = '/usr/lib/sendmail' ;
# This script was generated automatically by Perl Builder(tm): http://www.solutionsoft.com

# ***ENDAUTOGEN:HEADER*** Do NOT modify this line!!  You may enter custom code after this line.



# ***AUTOGEN:INPUT*** Do NOT modify this line!! Do NOT enter custom code in this section.

&GetFormInput;

# The intermediate variables below make your script more readable
# but somewhat less efficient since they are not really necessary.
# If you do not want to use these variables, clear the
# Intermediate Variables checkbox in the Tools | Options dialog box, CGI Wizard tab.

$first = $field{'first'} ;       
$last = $field{'last'} ;       
$company = $field{'company'} ;       
$email = $field{'email'} ;       
$whereheard = $field{'whereheard'} ;       
$athome = $field{'athome'} ;       
$atwork = $field{'atwork'} ;       
$submit = $field{'submit'} ;       

$message = "" ;
$found_err = "" ;

# ***ENDAUTOGEN:INPUT*** Do NOT modify this line!!  You may enter custom code after this line.



# ***AUTOGEN:VALIDATE*** Do NOT modify this line!! Do NOT enter custom code in this section.

$errmsg = "<p>Field 'first' must be filled in.</p>\n" ;

if ($first eq "") {
      $message = $message.$errmsg ;
      $found_err = 1 ; }


$errmsg = "<p>Field 'last' must be filled in.</p>\n" ;

if ($last eq "") {
      $message = $message.$errmsg ;
      $found_err = 1 ; }


$errmsg = "<p>Please enter a valid email address</p>\n" ;

if ($email !~ /.+\@.+\..+/) {
      $message = $message.$errmsg ;
      $found_err = 1 ; }

if ($found_err) {
      &PrintError; }


# ***ENDAUTOGEN:VALIDATE*** Do NOT modify this line!!  You may enter custom code after this line.



# ***AUTOGEN:EMAIL*** Do NOT modify this line!! Do NOT enter custom code in this section.

$recip = "webmaster\@yourownsite.com" ;

open (MAIL, "|$mail_prog -t");
print MAIL "To: $recip\n";
print MAIL "Reply-to: $email\n";
print MAIL "From: $email\n";
print MAIL "Subject: DownLoad Alert!\n";
print MAIL "\n\n";
print MAIL "The following user has downloaded Power Widget:\n" ;
print MAIL "\n" ;
print MAIL "Name: ".$first." ".$last."\n" ;
print MAIL "\n" ;
print MAIL "Company: ".$company."\n" ;
print MAIL "\n" ;
print MAIL "Where Heard about Power Widget: ".$whereheard."\n" ;
print MAIL "\n" ;
print MAIL "Use at home? ".$athome."\n" ;
print MAIL "Use at work? ".$atwork."\n" ;
print MAIL "\n\n";
close (MAIL);


$recip = $email ;

open (MAIL, "|$mail_prog -t");
print MAIL "To: $recip\n";
print MAIL "Reply-to: sales\@yourownsite.com\n";
print MAIL "From: sales\@yourownsite.com\n";
print MAIL "Subject: Power Widget\n";
print MAIL "\n\n";
print MAIL "Hi ".$first.",\n" ;
print MAIL "\n" ;
print MAIL "Thank you for downloading PowerWidget!\n" ;
print MAIL "\n" ;
print MAIL "Please contact us if you have any questions.\n" ;
print MAIL "\n" ;
print MAIL "Sincerely,\n" ;
print MAIL "\n" ;
print MAIL "Power Widget Sales Dept.\n" ;
print MAIL "\n\n";
close (MAIL);

# ***ENDAUTOGEN:EMAIL*** Do NOT modify this line!!  You may enter custom code after this line.



# ***AUTOGEN:HTML*** Do NOT modify this line!! Do NOT enter custom code in this section.
print "Location: www.download.com\nURI: www.download.com\n\n" ;

# ***ENDAUTOGEN:HTML*** Do NOT modify this line!!  You may enter custom code after this line.



# ***AUTOGEN:ERRPRINT*** Do NOT modify this line!! Do NOT enter custom code in this section.

sub PrintError {
print "Content-type: text/html\n\n";
print '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">'."\n" ;
print "<html>\n" ;
print "\n" ;
print "<head>\n" ;
print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'."\n" ;
print '<meta name="Author" content>'."\n" ;
print '<meta name="GENERATOR" content="Microsoft FrontPage 3.0">'."\n" ;
print "<title>Perl Builder Error Page Example</title>\n" ;
print "</head>\n" ;
print "\n" ;
print '<body bgcolor="#8080C0" text="#000000" link="#800000" vlink="#000080" alink="#800000">'."\n" ;
print "\n" ;
print '<p align="center"><font color="#FFFFFF" face="Arial"><big><strong>Processing Error</strong></big></font></p>'."\n" ;
print "\n" ;
print '<p align="left"><font face="Arial" color="#000080"><strong>You forgot to enter one or more'."\n" ;
print "values:</strong></font></p>\n" ;
print "\n" ;
print '<p align="left"><font color="#FFFFFF" face="Arial"><strong>'.$message.'</strong></font></p>'."\n" ;
print "\n" ;
print '<p align="left"><font face="Arial" color="#000080"><strong>Please click your browser\'s'."\n" ;
print "Back button and try again.</strong></font></p>\n" ;
print "</body>\n" ;
print "</html>\n" ;

exit 0 ;
return 1 ;
}

# ***ENDAUTOGEN:ERRPRINT*** Do NOT modify this line!!  You may enter custom code after this line.



# ***AUTOGEN:PARSE*** Do NOT modify this line!! Do NOT enter custom code in this section.
sub GetFormInput {

      (*fval) = @_ if @_ ;

      local ($buf);
      if ($ENV{'REQUEST_METHOD'} eq 'POST') {
            read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
      }
      else {
            $buf=$ENV{'QUERY_STRING'};
      }
      if ($buf eq "") {
                  return 0 ;
            }
      else {
             @fval=split(/&/,$buf);
            foreach $i (0 .. $#fval){
                  ($name,$val)=split (/=/,$fval[$i],2);
                  $val=~tr/+/ /;
                  $val=~ s/%(..)/pack("c",hex($1))/ge;
                  $name=~tr/+/ /;
                  $name=~ s/%(..)/pack("c",hex($1))/ge;

                  if (!defined($field{$name})) {
                        $field{$name}=$val;
                  }
                  else {
                        $field{$name} .= ",$val";
                        
                        #if you want multi-selects to goto into an array change to:
                        #$field{$name} .= "\0$val";
                  }


               }
            }
return 1;
}


# ***ENDAUTOGEN:PARSE*** Do NOT modify this line!!  You may enter custom code after this line.


0
Comment
Question by:ishallbe
4 Comments
 
LVL 1

Expert Comment

by:sdjjm
ID: 1830621
I don't see any syntax errors, and it's tough looking through a script and not being able find bugs by testing it.  Are you sure '/usr/lib/sendmail' is the correct location on your server for sendmail?  Also notice that "@yourownsite.com" (in 3 places) is not a valid domain for you to send mail from....
0
 
LVL 4

Expert Comment

by:mikem
ID: 1830622
Try to find out if the error still occurswhen placing

print "Content-type: text/html\n\n"; At the beginning of the program to see what the print "Location:" is.. It may be that the URL is invalid, or made invalid by the script.

I have had similar problems myself with the print "Location:" and have debugged it in this way..

Mike
0
 
LVL 8

Accepted Solution

by:
jhurst earned 100 total points
ID: 1830623
I may be missing something but it seems to me that unless there is an error your script does not output to stdout to be sent to the client.  Apache and evey other server that I have tested generates an error 500 if the script does not generate aan http header, such as
  Content-type: tex/html\n\n


0
 
LVL 3

Expert Comment

by:rickyr
ID: 1830624
use CGI::Carp qw(fatalsToBrowser);
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now