Solved

Internal Server Error (500)

Posted on 1999-01-15
4
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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