PDA

View Full Version : CGI for Apache - Premature end of script headers


ungureaa
Dec 15, 2005, 09:01 AM
I have a post form on my Web site in Common Gateway Interface (CGI) but when people click in order to post it, the message Premature end of script headers: mailform.cgi appears. If you'd like to see what I'm talking about please go to this page : http://www.accesss.net/pnjoindre.html.

How can I resolv this matter ? I have the codes so if you leave me the mail, I can post you the whole .cgi form.

Thanks !

psi42
Dec 15, 2005, 11:04 AM
Something is going wrong when your CGI script is executed. Check the apache logs and any other output the script is written to produce to see what is going on.

Roel Zylstra
Dec 15, 2005, 11:06 AM
Make sure that your script is returning something to the browser, starting with something equivalent to
print "Content-type: text/html\n\n";Or maybe you are trying to use sendmail with the wrong path or parameters?

If those don't work, try seeing a more detailed error message by including
use CGI::Carp qw(fatalsToBrowser);in your script.

ungureaa
Dec 15, 2005, 01:03 PM
Here is the bloody script - I HATE it ! What's wrong with it ? :mad:

#!/usr/local/bin/perl
# mailform.cgi
# Copyright (C) 1997 William E. Weinman
#
# generic CGI email generator
# change $malto, $subject, and $sendmail to use
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA.
#
# where to send the mail
$mailto = "[email protected]";
# a default subject line
$subject = "Message du Formulaire";
# your sendmail location. Ask your system administrator.
# or just try this, it works most of the time
$sendmail = "/usr/sbin/sendmail -t";

# DON'T MODIFY BELOW THIS LINE
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$mailfrom = $mailto;
$sendmaildashfokay = 1;
$program = "mailform.cgi";
$version = "1.0";
$byline = "(by Bill Weinman <wew\@bearnet.com>)";
print "content-type: text/html\n\n";
%q = getquery();
$emessage = "$subject:\n\n";
foreach $k (sort keys %q) {
$emessage .= "$k : $q{$k}\n"
}
$emessage .= "\n---\n Sent by $program $version $byline\n";
sendmessage();
done();
sub done
{
print <<HERE;
<title> $subject </title>
<body bgcolor=white>
<h1>$subject</h1>
<p> Your message has been sent.
<pre>
$emessage
</pre>
HERE
}
# sendmessage
#
# sends email to $mailto from $mailfrom
# with $subject and $emessage
#
sub sendmessage
{
$dashf = $sendmaildashfokay ? "-f $mailfrom" : "";
open(SENDMAIL, "|$sendmail $dashf") or die "can't open $sendmail\n";
print SENDMAIL "X-Mailer: $program $version $byline\n";
print SENDMAIL "From: $mailfrom\n";
print SENDMAIL "To: $mailto\n";
print SENDMAIL "Subject: $subject\n";
print SENDMAIL "\n";
print SENDMAIL "$emessage\n";
close SENDMAIL;
}

# getquery
#
# returns hash of CGI query strings
#
sub getquery
{
my $method = $ENV{'REQUEST_METHOD'};
my $query_string, $pair;
my %query_hash;
my $sep = $/;
undef $/;
$query_string = $ENV{'QUERY_STRING'} if $method eq 'GET';
$query_string = <STDIN> if $method eq 'POST';
$/ = $sep;
return undef unless $query_string;
foreach $pair (split(/&/, $query_string)) {
$pair =~ s/\+/ /g;
$pair =~ s/%([\da-f]{2})/pack('c',hex($1))/ieg;
($_qsname, $_qsvalue) = split(/=/, $pair);
$query_hash{$_qsname} = $_qsvalue;
}
return %query_hash;
}

psi42
Dec 20, 2005, 12:59 PM
The script looks fine to me. Have you checked the apache logs like I suggested?

ungureaa
Dec 23, 2005, 04:45 PM
No because I don't know how to check it... :(

psi42
Dec 25, 2005, 07:20 PM
No because I don't know how to check it...:(

Do you have root/administrator privileges on the server?

What operating system is the server running?

Roel Zylstra
Dec 25, 2005, 10:41 PM
Or did you try any of the things I suggested?

ungureaa
Dec 26, 2005, 09:37 AM
Yes I have administrator rights and the system runs with Apache. But because I'm new on that, I don't know what I can run a script nor how to look for http headers.
Thanks !

psi42
Dec 26, 2005, 12:04 PM
Yes I have administrator rights and the system runs with Apache. But because I'm new on that, I don't know what I can run a script nor how to look for http headers.


What operating system is the server running?
Also, did you try what admin suggested?

ungureaa
Dec 26, 2005, 12:21 PM
I don't know about the server, it is a provider that can tell that. My rights are to modify any file that goes on my web site www.accesss.net
I did what admin told me but it didn't work any better. I might also ask where should I put those phrases in my script?
Thanks !

psi42
Dec 26, 2005, 12:31 PM
I don't know about the server, it is a provider that can tell that. My rights are to modify any file that goes on my web site www.accesss.net
I did what admin told me but it didn't work any better. I might also ask where should I put those phrases in my script?
Thanks !

Okay, so you don't have administrator privileges on the server? Can you actually log into the machine that runs apache?

ungureaa
Dec 26, 2005, 12:36 PM
No I cannot, and even if I could, I don't know much about Apache

psi42
Dec 26, 2005, 02:10 PM
No I cannot, and even if I could

Okay, so you have no access to the server's logs?

Sigh... I suppose we'll have to do this the hard way. See, errors encountered by the perl interpreter should be logged to the apache logs, so we could see what is going on.

Again, have you tried what admin suggested?


I don't know much about Apache
I'd _really_ suggest you read up on it. CGI is pretty dangerous stuff, and you should make sure you know what you are doing before publishing a public CGI script. ;)