Connecting Tech Pros Worldwide Forums | Help | Site Map

Can't Write Text File

Google Mike
Guest
 
Posts: n/a
#1: Jul 17 '05
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.

Guest
 
Posts: n/a
#2: Jul 17 '05

re: Can't Write Text File


> Can someone go over the steps required to make this function work[color=blue]
> (Linux security-wise)? Or does one see another problem?[/color]

What are the permissions on the file?

--Wil


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Can't Write Text File


googlemike@hotpop.com (Google Mike) wrote in message news:<25d8d6a8.0406211141.348c451b@posting.google. com>...[color=blue]
> 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`;
> }[/color]

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
Google Mike
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Can't Write Text File


ng4rrjanbiah@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<abc4d8b8.0406212046.6a044187@posting.google. com>...[color=blue]
> googlemike@hotpop.com (Google Mike) wrote in message news:<25d8d6a8.0406211141.348c451b@posting.google. com>...[color=green]
> > 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`;
> > }[/color]
>
> 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>[/color]

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.
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Can't Write Text File


googlemike@hotpop.com (Google Mike) wrote in message news:<25d8d6a8.0406280730.79cd887c@posting.google. com>...
<snip>[color=blue][color=green][color=darkred]
> > > `echo "$sMsg" >> $sLogFile`;
> > > }[/color]
> >
> > 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>[/color]
>
> Nice complement -- thanks.[/color]

Sorry for the late reply.
[color=blue]
> My promotion has kept me so busy I cannot
> reciprocate my knowledge as much as I had liked.[/color]

Nice to know about your promotion...
[color=blue]
> 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.[/color]

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
Closed Thread