473,378 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Can't Write Text File

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
4 5746
> 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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gurk | last post by:
hallow all i'm using a common dialog to save data into a text file. for so far i have this, but can someone give me a simpe exaple what i have to do after the line Open cdl.FileName For Output...
3
by: Leo Muller | last post by:
Hi, How can I write text from code behind without getting HTML tags added to it? Up till now I used the label control. But when I call the label.text = "something" then the HTML will output...
2
by: Jukka58 | last post by:
Hello! We have two computers and two programmers. One programmer for Ms Access 2000 and one programmer VB6 pro and applicartion. Access database is large system and i not will transfer data to...
2
by: Microsoft | last post by:
I am trying to use the streamwriter to write to a text file I declare the streamwriter publically at the beginning im filename As String Dim Drive As String Dim oFile As System.IO.File
10
by: . | last post by:
Yes, now you can with LocaWapp (and async Ajax): http://daviderognoni.blogspot.com/?locawapp jsFileWrite("testJsFile.txt","This is a test."); alert(jsFileRead("testJsFile.txt"));
3
by: ayham | last post by:
I can't Write to XML File using ASP.NET becouse my OS(win xp) tell me that the user(account) that is ASP.net haven't the right to access the file -- ayham...
0
by: piyush bharadwaj | last post by:
Hi friends , i want to creat a new excel file and than import data from text file in C#.Net plz help me
1
by: zman77 | last post by:
Hi. I have a windows service that I wrote in C#. After I successfully compile it, I install it using InstallUtil, then run it with the net start command. I am trying to either log some stuff to a...
0
by: Autostrad | last post by:
Can anybody tell me how to open (print)a text file to the screen. For example, to click a botton and the file will be shown in the screen. Using something like the code below. private:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.