Archived

This topic is now archived and is closed to further replies.

yves032784

PERL help

Recommended Posts

alright...i know this is not game related but i need some help concerning perl basically i''m trying to get my perl script to post some text to and html file, when i access it from command line, it works, but when i have it executed through the web it doesnt work (i''m running slackware 9.1, kernel 2.6.4, apache, 1.3.29) this is my code:
#!/usr/bin/perl -w
#
require "cgi-lib.pl";

&ReadParse (*input);

$file=''/usr/local/apache/htdocs/index.html'';
open(INFO, ">>$file");

print INFO ''<table cellspacing="1" cellpadding="5" border="0" bgcolor="#000000"
print INFO ''<tr bgcolor="#EEEEEE" ><td height="130" width="100" align="center"

print INFO ''<td rowspan="2" width="870"  valign="top" >'';
$sFormInput = $input{''TextPost''};
print INFO $sFormInput;
print INFO ''</table>'';
print INFO ''
'';

close(INFO);
 
this is my error log entry when i have it run through the web: print() on closed filehandle INFO at /usr/local/apache/cgi-bin/newpost.pl line 10 print() on closed filehandle INFO at /usr/local/apache/cgi-bin/newpost.pl line 11 print() on closed filehandle INFO at /usr/local/apache/cgi-bin/newpost.pl line 13 print() on closed filehandle INFO at /usr/local/apache/cgi-bin/newpost.pl line 15 print() on closed filehandle INFO at /usr/local/apache/cgi-bin/newpost.pl line 16 print() on closed filehandle INFO at /usr/local/apache/cgi-bin/newpost.pl line 17 [Sun Mar 21 13:32:10 2004] [error] [client 192.168.2.154] Premature end of script headers: /usr/local/apache/cgi-bin/newpost.pl what''s wrong with my code? Or should i chmod index.html to another user...if so...which user? and what chmod command should i give?

Share this post


Link to post
Share on other sites
You should check for errors generated by open, cause it definitely looks like the file isn''t opened properly.

open(INFO, ">>$file") or die("failed to open file: $!");

$! is a variable containing an error message.

Share this post


Link to post
Share on other sites
open(INFO, ">>$file");

doesnt create the file if it doesnt already exist.


# > write mode, creats file if needed. Overwrites file if exists. Cant read, only write.
# < read mode. DEFAULT. Cant write, offly read.
# >> append mode. Doesnt create file. Appends output to bottom of file.
# +>> read/append mode. Doesnt create file. Appends output to bottom of file.
# +> read/write mode. When file is going to be written and read from many times. On opening, contents are lost.

Share this post


Link to post
Share on other sites
i know for sure the file exists. when i execute the perl script from command line, index.html gets updated. I tried the "or die("failed to open file: $!") " didnt make a difference

Share this post


Link to post
Share on other sites
Does your cgi process have the proper permissions to open /usr/local/apache/htdocs/index.html?

Share this post


Link to post
Share on other sites
this is my error message...


Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@P100Server.mtmc.phub.net.cable.rogers.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/1.3.29 Server at P100Server.mydomain.org Port 80


how do i set permision?

Share this post


Link to post
Share on other sites
That is not the error message related to the script, it''s an error message related to the fact that webserver failed to execute the script properly. Check the server log file for the error messasge from the script itself.

And permissions are set by chmod. Check the man pages.

Share this post


Link to post
Share on other sites
chmod can be used to give global, user or group permissions to write to the file. You can use chown to change the user or group associated with the file.

Share this post


Link to post
Share on other sites
er....i''m still a bit of a linux newb

i tried chmod +x index.html
i even tried (under /usr/local/apache) chmod 755 htdocs

no change in the error message

Share this post


Link to post
Share on other sites
Check who''s the owner of the file you''re trying to write to. If it''s not "www" (assuming that''s the user the web server is running as), and that file does not have write permissions, the web server is not allowed to open the file for writing.

As I said, check the web servers error log to see what the error message from the script is. If it says something about permission denied, then I fairly sure this is what''s wrong.

And also, the script must output a content type header before anything else is outputted. That is what "premature end of script headers" is about.

print "content-type: text/html\n\n";

Share this post


Link to post
Share on other sites