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
Solved

Internal Server Error (500)

Posted on 1999-01-15
4
183 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

809 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