Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Internal Server Error (500)

Posted on 1999-01-15
4
Medium Priority
?
193 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 200 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article will show, step by step, how to integrate R code into a R Sweave document
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)
Suggested Courses

782 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