Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Premature end of script headers

Status
Not open for further replies.

force5

ISP
Nov 4, 2004
118
US
I am using Matt Wright's formmail.pl and I am getting a "Server Error; Error 500 : Premature end of script headers: The Server encountered an internal error and was unable to complete your request". I checked the error_log in Apache and it says Premature end of script headers: formmail.pl, referer:
I have searched the whole file but I can't find the answer. Any suggestions?

Thanks
 
You could try putting
Code:
use CGI::Carp qw(fatalsToBrowser);
in your script, this should give you a more useful error message than a standard 500 error. Also test the script using Warnings and Strict usually helps iron out any obvious conflicts.

Rob Waite
 
thanks waiterm...are you speaking of putting that code in the actual formmail.pl?
I'm not sure how to implement Warnings and Strict. I rememeber reading about it in mod_perl. Can you please give me some more details?
Thanks for the help.
 
Code:
;
use Warnings;
use Strict;
There's quite a lot of info out there if you Google for it.

That snippet I gave you before, yes put it in the formmail.pl, I would imagine you have other module calls (i.e. lines beginning with 'use', so pop it in just underneath those.

Rob Waite
 
Code:
use warnings;
use strict;

No caps

HTH
--Paul


Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
The other guys' advice is good, and will help you fix all sorts of problems when coding Perl. They won't necessarily help you with the "Premature end of script headers" though.

(I think) you get this message when the server completely fails to execute the script in question - the server sends a header saying "here comes a document...", then dies. Two common causes of this (on Unix/Linux hosts) would be:

1) You have forgotten to give "execute" permission to the script file. Look for a "chmod" function in your ftp program to do this.

2) The "path to Perl" in your script is wrong. The first line of your script is something like
Code:
#!/usr/bin/perl
This tells the server that this is a Perl script, to be interpreted by the program at [tt]/usr/bin/perl[/tt], rather than some other kind of script. If that isn't the location of Perl on your server, it isn't going to work. Check with your host to find out what you should be putting.



-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Other causes for this problem are

1) Not printing a correct HTTP header
2) Printing something else before the HTTP header

Code:
#!/usr/bin/perl
use CGI;
$q=new CGI;
print $q->header;
print $q->"hello world";
is the same as
Code:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "Hello World";

HTH
--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top