»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 01-01-2004, 10:50 AM   #1 (permalink)
Banned
 
Siliconjunkie's Avatar
 
Join Date: Feb 2003
Location: Houston, TX
Posts: 1,595
Siliconjunkie is on a distinguished road
Send a message via AIM to Siliconjunkie
Perl/CGI help

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;

Siliconjunkie is offline   Reply With Quote
Old 01-02-2004, 07:19 AM   #2 (permalink)
Banned
 
Siliconjunkie's Avatar
 
Join Date: Feb 2003
Location: Houston, TX
Posts: 1,595
Siliconjunkie is on a distinguished road
Send a message via AIM to Siliconjunkie
Bueller?
Siliconjunkie is offline   Reply With Quote
Old 01-02-2004, 08:15 AM   #3 (permalink)
Registered User
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Champaign, IL
Posts: 3,253
jkrohn is on a distinguished road
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
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
__________________
Jkrohn
jkrohn is offline   Reply With Quote
Old 01-02-2004, 08:24 AM   #4 (permalink)
Registered User
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Champaign, IL
Posts: 3,253
jkrohn is on a distinguished road
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
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
__________________
Jkrohn
jkrohn is offline   Reply With Quote
Old 01-02-2004, 09:22 AM   #5 (permalink)
Banned
 
Siliconjunkie's Avatar
 
Join Date: Feb 2003
Location: Houston, TX
Posts: 1,595
Siliconjunkie is on a distinguished road
Send a message via AIM to Siliconjunkie
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.
Siliconjunkie is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 04:49 PM.