Solved

Internal Server Error (500)

Posted on 1999-01-15
4
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
use CGI::Carp qw(fatalsToBrowser);
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

7 Experts available now in Live!

Get 1:1 Help Now