I am trying to get a form processing script to work and its giving me fits. Details below:
RedHat 7.3, Apache 1.3.something, perl in /usr/bin/perl
Tried making the cgi and the results file 777 and same problem exists. I also can run it just fine from the shell. It keeps throwing 500's when you hit it with the browser.
Apache log says:
Code:
[Thu Jan 1 11:36:24 2004] [error] [client 24.27.xxx.xxx] Premature end of script headers: /home/hamhost/public_html/cgi-bin/test.cgi
Here is the script, I have cut and pasted it into a new file in VI to make sure any windows was off of it.
Code:
#!/usr/bin/perl
$link ="http://www.hamhosting.net/";
# this is where the info will be written to - you need to specify a real directory
$file ="/home/hamhost/public_html/cgi-bin/requests.txt"; #must be read/writable
#
##################################################################
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$contents{$name} = $value;
}
}
chop($date = `date`);
# Now with the program
###########################################################
# Has to output a Content-type
print "Content-type: text/html\n\n ";
# Check to see if all required information was entered
# If you want a field to be required, add it here.
&no_cigar unless $contents{'name'};
&no_cigar unless $contents{'call'};
&no_cigar unless $contents{'street'};
&no_cigar unless $contents{'city'};
&no_cigar unless $contents{'state'};
&no_cigar unless $contents{'zip'};
&no_cigar unless $contents{'country'};
&no_cigar unless $contents{'phone'};
sub no_cigar
{
print <<"HTML";
<HTML><HEAD><TITLE>Form Incomplete</TITLE></HEAD>
<BODY>
<H1>Form Incomplete</H1>
I'm sorry, the form was not filled completely.<br>
Please Return to the form and fill it out completely.<p>
Thank you.
<HR>
<a href=\"$contents{'url'}\">Return to the $contents{'formname'} page</a>
</BODY></HTML>
HTML
exit;
}
# They go here if the form was submitted
# successfully. Now this page will send them
# off to where ever specify in the "link" field above.
print <<"HTML";
<HTML><HEAD><TITLE>Entry successful</TITLE></HEAD>
<BODY>
<H1>Request successful!</H1>
<p>
<hr noshade>
<p>
<H2>$contents{'name'}, I have received your request!</H2>
Your information will be processed soon,
<b>$contents{'name'}</b>. Thank you.
<p>
<HR noshade>
<A HREF=\"$link\">Back to the home page</A>.
</BODY>
</HTML>
HTML
#print "Content-type: text/plain\n\n ";
open(OUTPUT, ">>$file");
print OUTPUT "_______________________________\n";
print OUTPUT "Date: $date\n";
print OUTPUT "FORM NAME: $contents{'formname'}\n";
print OUTPUT "NAME: $contents{'name'}\n";
print OUTPUT "CALLSIGN: $contents{'call'}\n";
print OUTPUT "EMAIL: $contents{'email'}\n";
print OUTPUT "STREET: $contents{'street'}\n";
print OUTPUT "CITY: $contents{'city'}\n";
print OUTPUT "STATE: $contents{'state'}\n";
print OUTPUT "POSTAL CODE: $contents{'zip'}\n";
print OUTPUT "COUNTRY: $contents{'country'}\n";
print OUTPUT "PHONE: $contents{'phone'}\n";
close (OUTPUT);
exit;