ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: Unable to write to files using CGI
by Francisco Zarabozo other posts by this author
Mar 31 2008 10:11PM messages near this date
Unable to write to files using CGI | Unable to write to files using CGI
Hi Alejandro,

Sometimes, when a CGI script dies after having successfully printed some 
content to STDOUT in a web server, it seems like it just stopped without 
errors, but it's actually aborting with errors that you can only see in your 
httpd logs.

If you get confused about this, I recommend the following points:


1. Add this line at the beginning of your script:

use CGI::Carp qw(fatalsToBrowser); # This will show errors on the screen


2. Whenever you "open" a filehandle, send the actual error message to the 
"die" instruction through the special var "$!" like this:

open (FILE, "> myFile.txt") or die ("Cannot open myFile.txt: $!");


If you follow those two points, you're probably going to see the problem 
right in your screen and you'll have a better idea of what the problem is.

Anyway, you have to look at your httpd logs to be absolutely sure. If 
warnings are sent during your script execution, they will be shown only on 
those logs because they're not fatal errors and might not stop the execution 
at all. If you are using Apache, look into httpd.conf to see where the logs 
for that specific URL are supposed to be written.


P.S. Also, you should always use "strict" and "warnings" and test your 
scripts when possible in command line in order to catch obvious problems 
before going through your web server. You can at least check if your syntax 
is correct by calling "perl -wc yourscript.pl". While developing a script, 
the use of "diagnostics" is a good idea to get better information about your 
script errors or warnings (use strict; use warnings; use diagnostics;) - 
...or die ;-).

HTH

Paco Zarabozo



--------------------------------------------------
From: Alejandro Santillan Iturres
Sent: Monday, March 31, 2008 4:29 PM
To: ActivePerl@[...].com
Subject: Unable to write to files using CGI


I have a CGI script that worked perfect for several years that writes
contents of a file from the web on one webserver.
I am setting a new web server, and running this time the same script
but under https instead of http.
The script is very simple:


#!/usr/bin/perl
use CGI;
my $q = new CGI;
print $q-> header();

$user = $q-> param('user');
$pass = $q-> param('pass');

if($user eq "Eduard" && $pass eq "xxxxx"){
$filecontents = $q-> param('filecontents');

open(FILE,"> /home/server/file.txt") or die;
print FILE $filecontents;
close(FILE);

print "hi $user!";
}
else{print "You are not authorized!"}

So, you provide something like:
http://somewebserver.com/cgi-bin/xxx.cgi?user=Eduard&pass=xxxxx&filecontents=somedatakdfjlsd
kf
This way, it should create a file called "file.txt" at the directory /
home/server/file.txt

In the new server under https I do:
https://somewebserver.com/cgi-bin/xxx.cgi?user=Eduard&pass=xxxxx&filecontents=somedatakdfjls
dkf
But now nothing happens. The script writes only once hi Eduard!

The second print is ignored and I am not able to write or modify the
file.
I don't know if this happens because of the https. I've set the
permissions of /home/server dir to 777, and also the same for all
files inside the directory, but
I cannot write a file inside this directory.

What should I do to know what's going wrong?

Any help appreciated!

Best regards,

Alejandro


_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs 

_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Alejandro Santillan Iturres
Francisco Zarabozo
David Christensen
Bill Luebkert
Andy Bach
Alejandro Santillan Iturres

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved