Premature ending of script headers....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rse2
    New Member
    • Oct 2011
    • 4

    Premature ending of script headers....

    Hello, I am having a lot of trouble with getting a file to load. When i try it says internal server error.
    When i go to error logs to check what the problem is, it say premature ending of script headers.

    I tried changing the permissions to 755.
    I think i fixed all the syntax errors.

    it still won't work. :(

    Here is the page
    Code:
    #!/usr/bin/perl
    
    use 5.006;
    
    
    #! /usr/bin/perl 
    
    &form_parse;
    	$firstnumber = $FORM{'firstnumber'};
            $secondnumber = $FORM{'secondnumber'};
            $operation = $FORM{'operation'};
    
    
    print "Content-type: text/html\n\n";
    
    
    
    
    
    &printconfirmation;
    
    
    
    
    
    ############################################################
    # CONFIRMATION PAGE
    ############################################################
    sub printconfirmation {
    print <<ENDCONFIRMATIONPAGE;
    
    <html>
    <head>
    <title>Demo Confirmation Page</title>
    <style>
    td {
      background-color: white;
    font-size: 16pt;
    }
    input { font-size: 16pt; background-color: #E7CFCF; color: #FF6633; }
    select { font-size: 16pt; background-color: #E7CFCF; color: #FF6633; }
    textarea { font-size: 16pt; background-color: #E7CFCF; color: #FF6633; }
    </style>
    </head>
    <body bgcolor="white" text="#FF6633" alink="#FF6633" vlink="#FF6633">
    <br><p><br>
    <p><center><h1><b>The answer is: $firstnumber</b>  </h1></center>
    <P ALIGN="center"><p>$answer<br>
    <p><br><p>
    </P>
    
    <P><br>
    <BR><P>
    </body>
    </html>
    
    
    ENDCONFIRMATIONPAGE
    }
    
    
    ############################################################
    # FORM PARSE
    ############################################################
    sub form_parse  {
            read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
            @pairs = split(/&/, $buffer);
            foreach $pair (@pairs){
                ($name, $value) = split(/=/, $pair);
                $value =~ tr/+/ /;
            $value =~ s/\'//g;
                $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
                $FORM{$name} = $value;
            }
    }
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    First thing, you have two of the following line:

    Code:
    #!/usr/bin/perl
    The second one has a space in it, which is incorrect syntax, and it is actually considered a comment if not on the first line of the file. So, delete the 2nd one with the space in it.

    Next, is there a reason you are defaulting to such an old version of Perl (5.006)?

    You should have the following two lines after the initial shebang line:

    Code:
    use strict;
    use warnings;
    Only with those two lines will you know you have gotten all of the extraneous errors out of the way.

    If you are trying to execute this as cgi, you will have to first ensure that your web server is setup to server .cgi or .pl files. If you are on apache, there are plenty of guides on the internet for configuring it correctly.

    Regards,

    Jeff

    Comment

    • RonB
      Recognized Expert Contributor
      • Jun 2009
      • 589

      #3
      In addition to Jeff's suggestions, you should use the CGI module for parsing the form submission instead of your form_parse sub. That method of form parsing has been depreciated for more than 10 years.

      While debugging cgi scripts, your should use the CGI::Carp module to redirect the errors to the browser.

      The beginning of a cgi script should look like this:
      Code:
      #!/usr/bin/perl
      
      use strict;
      use warnings;
      use CGI;
      use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
      
      # The CGI module provides several methods to parse the form submission
      # Here's my preference.
      my $cgi = CGI->new;
      my %form = $cgi->Vars;

      Comment

      Working...