Perl/CGI help  | |
January 1st, 2004, 01:50 PM
|
#1 (permalink)
| | Did you try Google yet?
Join Date: Feb 2003 Location: Buckhannon, WV
Posts: 3,468
|
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; |
| |
January 2nd, 2004, 10:19 AM
|
#2 (permalink)
| | Did you try Google yet?
Join Date: Feb 2003 Location: Buckhannon, WV
Posts: 3,468
|
__________________
My computer is bigger than yours!
|
| |
January 2nd, 2004, 11:15 AM
|
#3 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
|
Works absolutely fine for me on both of my webservers. Nothing looks wrong with the script either.
Is premature end of script headers the only thing found in the error log?
Try putting this line at the top and not farther down.
print "Content-type: tect/html\n\n";
You are seeing the beauty of perl right now. It always loves to do this
Jkrohn
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
|
| |
January 2nd, 2004, 11:24 AM
|
#4 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
|
Another thing you can do it use #!/usr/bin/perl -w
This will print warnings into the log as well. This could clue you into where your installation of perl is going awry.
Jkrohn |
| |
January 2nd, 2004, 12:22 PM
|
#5 (permalink)
| | Did you try Google yet?
Join Date: Feb 2003 Location: Buckhannon, WV
Posts: 3,468
|
Turns out it was an ownership issue. It was owned by root and even with 777 Apache refused to execute it. Chowned it and all is well. Thanks for the help. |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |