home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Perl/CGI help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2274
Discussions: 200,937, Posts: 2,379,254, Members: 246,302
Old January 1st, 2004, 01:50 PM   Digg it!   #1 (permalink)
Did you try Google yet?
 
Siliconjunkie's Avatar
 
Join Date: Feb 2003
Location: Buckhannon, WV
Posts: 3,468
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 January 2nd, 2004, 10:19 AM     #2 (permalink)
Did you try Google yet?
 
Siliconjunkie's Avatar
 
Join Date: Feb 2003
Location: Buckhannon, WV
Posts: 3,468
Send a message via AIM to Siliconjunkie
Bueller?
__________________
My computer is bigger than yours!
Siliconjunkie is offline   Reply With Quote
Old January 2nd, 2004, 11:15 AM     #3 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,552
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
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
jkrohn is offline   Reply With Quote
Old January 2nd, 2004, 11:24 AM     #4 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,552
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 is offline   Reply With Quote
Old January 2nd, 2004, 12:22 PM     #5 (permalink)
Did you try Google yet?
 
Siliconjunkie's Avatar
 
Join Date: Feb 2003
Location: Buckhannon, WV
Posts: 3,468
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2907)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Wireless Televisions. (8)
California Passes Anti-Flat-HDTV Le.. (43)
Obama the Muslim (14)
Is the PSU I received dead? (11)
windows vista security holes (9)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
Recent Discussions
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Regular Build (4)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
Wireless Televisions. (8)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)


All times are GMT -4. The time now is 12:59 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28