By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,028 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,028 IT Pros & Developers. It's quick & easy.

Can't Write Text File

P: n/a
I have PHP version 4.2.2 that ships with RH9. I want to have it write
to a file like this:

function WriteLog($sLogFile, $sMsg) {

if (substr($sLogFile,1,1) != '/') {
$sLogFile = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) .
$sLogFile;
}
`echo "$sMsg" >> $sLogFile`;
}

On one workstation, I have this working great and it dumps a log file
inside the web directory where this function exists, appending data to
it. On another workstation, it doesn't write to the file. I checked
security settings and these are the same. I then bounced the httpd and
still no luck. I then created the file with touch and tried to see if
that worked, but no luck. I then used "test" instead of "$sMsg" to see
if that would work, but no luck.

Can someone go over the steps required to make this function work
(Linux security-wise)? Or does one see another problem?

Sure, I could open a file handle and write a file, but I wanted to go
this route.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> Can someone go over the steps required to make this function work
(Linux security-wise)? Or does one see another problem?


What are the permissions on the file?

--Wil
Jul 17 '05 #2

P: n/a
go********@hotpop.com (Google Mike) wrote in message news:<25**************************@posting.google. com>...
I have PHP version 4.2.2 that ships with RH9. I want to have it write
to a file like this:

function WriteLog($sLogFile, $sMsg) {

if (substr($sLogFile,1,1) != '/') {
$sLogFile = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) .
$sLogFile;
}
`echo "$sMsg" >> $sLogFile`;
}


Perhaps because of safe mode problem??
<http://in2.php.net/features.safe-mode>

<OT>BTW, nice to you again here:-) We missed your valuable
tutorials. Hope, the employment condition in US is ok now.</OT>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

P: n/a
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>...
go********@hotpop.com (Google Mike) wrote in message news:<25**************************@posting.google. com>...
I have PHP version 4.2.2 that ships with RH9. I want to have it write
to a file like this:

function WriteLog($sLogFile, $sMsg) {

if (substr($sLogFile,1,1) != '/') {
$sLogFile = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) .
$sLogFile;
}
`echo "$sMsg" >> $sLogFile`;
}


Perhaps because of safe mode problem??
<http://in2.php.net/features.safe-mode>

<OT>BTW, nice to you again here:-) We missed your valuable
tutorials. Hope, the employment condition in US is ok now.</OT>


Nice complement -- thanks. My promotion has kept me so busy I cannot
reciprocate my knowledge as much as I had liked.

We found that if we allowed the "apache" user on RH9 Linux to have the
power to do /bin/echo, using the sudo and /etc/sudoers technique, it
permitted PHP web pages to do this. HOWEVER, we found a BUG where it
would intermittently write either one or two messages for a given
echo. HOWEVER, if we spawned with popen into a new thread, and had
that thread do command-line PHP under root to write output to a text
file, this would consistently work around the double-echo problem.
Also, when we used normal file output commands with fwrite or fputs,
under the apache web session, it would also write to the file in this
double fashion, intermittently. Weird. We're also in a situation right
now where we can't upgrade. So, anyway, this file output was just a
stub to get us through a period of time before I would rewrite the
code so that it sent an email, rather than stored data in a text file.
We'll just work around the issue for now.
Jul 17 '05 #4

P: n/a
go********@hotpop.com (Google Mike) wrote in message news:<25**************************@posting.google. com>...
<snip>
`echo "$sMsg" >> $sLogFile`;
}
Perhaps because of safe mode problem??
<http://in2.php.net/features.safe-mode>

<OT>BTW, nice to you [see] again here:-) We missed your valuable
tutorials. Hope, the employment condition in US is ok now.</OT>


Nice complement -- thanks.


Sorry for the late reply.
My promotion has kept me so busy I cannot
reciprocate my knowledge as much as I had liked.
Nice to know about your promotion...
We found that if we allowed the "apache" user on RH9 Linux to have the
power to do /bin/echo, using the sudo and /etc/sudoers technique, it
permitted PHP web pages to do this. HOWEVER, we found a BUG where it
would intermittently write either one or two messages for a given
echo. HOWEVER, if we spawned with popen into a new thread, and had
that thread do command-line PHP under root to write output to a text
file, this would consistently work around the double-echo problem.
Also, when we used normal file output commands with fwrite or fputs,
under the apache web session, it would also write to the file in this
double fashion, intermittently. Weird. We're also in a situation right
now where we can't upgrade. So, anyway, this file output was just a
stub to get us through a period of time before I would rewrite the
code so that it sent an email, rather than stored data in a text file.
We'll just work around the issue for now.


Sounds like a nice research. I'm not good in *nix and so couldn't
understand much. Anyway, nice to know you've sorted it out.

--
"Believe it or not, patriotism is one of the worst dividing forces"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.