Page 1 of 1
PHP Read Write Protection Error
Posted: Tue Jan 06, 2004 8:12 pm
by webwasp
I am trying to set up individual page counters so that I can tell how many times a particular page has been accessed.
As a test I have a simple php page which is working correctly –The php page is suppose to update a txt file every time it is hit. The txt file appears to be write protected so the txt file does not open or update. Is there anyway of resolving this. Please try the test page located at:
http://www.webwasp.co.uk/counter/
The php script is as follows:
<html>
<head>
<title>php test page</title>
</head>
<body>
<?php
echo "new program <br>";
$counterFile='counter.txt';
if($cfHandler=@fopen($counterFile,'r+'))
{
$visitors=fread($cfHandler,filesize($counterFile));
settype($visitors,'integer');
print($visitors.' visitors todate');
rewind($cfHandler);
fwrite($cfHandler,++$visitors);
fclose($cfHandler);
}
else{echo "could not open counter.txt Why not?? any help please...";};
?>
</body>
</html>

Posted: Tue Jan 06, 2004 8:40 pm
by scorphus
1 - Try to remove that @ before fopen($counterFile,'r+')) and let us know what error is being rised
2 - What are the webserver's user access permission to this file and to it's directory?
3- What system are you running?
Regadrs,
Scorphus.
update
Posted: Wed Jan 07, 2004 4:45 am
by webwasp
Hey cheers for your reply it's much appreciated and all that...
1 - I removed the @ before fopen($counterFile,'r+')) and message was as follows:
new program
Warning: fopen(counter.txt): failed to open stream: Permission denied in /home/webwasp_co_uk/counter/index.php on line 9
could not open counter.txt Why not?? any help please...
2 - What are the webserver's user access permission to this file and to it's directory?
I don't know what you mean by webserver's user access permission?
3- What system are you running?
I access the site through Dreamweaver (either MX or MX 2004). This is running on a PC with Windows XP.
Does that make things clearer??

webwasp
Posted: Wed Jan 07, 2004 4:57 am
by m3mn0n
Write a script to create a file. That will make sure you have read/write access to it. Currently, you don't.
Reference: [php_man]filesystem[/php_man] functions
Posted: Wed Jan 07, 2004 5:24 am
by webwasp
How do I create a script that will write a file if I don't have read write permission?
Sorry I'm new to all this...

Re: update
Posted: Wed Jan 07, 2004 6:03 am
by scorphus
webwasp wrote:Warning: fopen(counter.txt): failed to open stream: Permission denied
I don't know what you mean by webserver's user access permission?
Does that make things clearer??
Sure!
1 - As you and dear mate Sami noticed, your web application (indeed the webserver's user) doesn't have write access to counter.txt (maybe neither to the directory which contains it, what is also relevant)
2 - Webserver's user is the user that runs the webserver (Apache?) on the system. Whenever your web application try to create or write to files, it is done by this user. So if this user has not write access to a file you will receive an error of that kind (Permission denied).
3 - It is important to know what system is running your web application, what system runs on your server. This include the OS, webserver etc.
Cheers,
Scorphus.
Technical Info
Posted: Wed Jan 07, 2004 8:21 am
by webwasp
My ISP has the following info posted about the system:
We are running PHP version 4.3.2 with safe mode on and register_globals off. Safe mode means that you can only read or write files that are owned by you, amongst other things (note that if you need to upload? files these files will be created by, and owned by, the nobody user). You should use PHP's own mail functions rather than trying to call sendmail directlry.
Register_globals off means that you cannot rely on any CGI parameters automatically creating variables; you have to explicitly access $_GET or $_POST.
Both of these features, while occasionally awkward, are vital security measures on a shared server.
System: Linux superultra1 2.4.21
Server API: Apache
All that 'nobody user' stuff is all a bit confusing...

Posted: Wed Jan 07, 2004 9:25 am
by scorphus
Such a sufficient information.
The user/group nobody/nobody is commonly used to run the webserver. The access permissions of a visitor of your page is the access permission of this nobody user.
You should be accessing the server through Dreamweaver's FTP built-in feature. I can't remember if it is possible to manage file/directory access permissions using DW, but if you have an FTP client (such as WSFTP_LE or LeapFTP) you can change the permission of counter.txt and grant write access for the nobody user.
Can you change the file/directory access permission? Do you have some experience with FTPing? I'll take a look for some tutorial on using this feature on an FTP client.
Leaving for lunch, back in one hour,
Scorphus.
Posted: Wed Jan 07, 2004 11:25 am
by scorphus
Here are ome tutorials and some mailling list threads on those subjects:
- [google]ftp tutorial chmod[/google]
- [mail_search]ftp chmod[/mail_search]
- [mail_search]failed to open stream: Permission denied[/mail_search]
Hope this helps. Looking forward hearing from you...
Posted: Wed Jan 07, 2004 3:45 pm
by webwasp
Cheers for the help – I will follow the links and check back. to let you know how I get on
I don’t think it is possible to change the read write permissions in DW. Are any of the programs (such as WSFTP_LE or LeapFTP) you mentioned freebies?

Posted: Wed Jan 07, 2004 4:07 pm
by scorphus
You are welcome, WSFTP_LE (
http://www.ipswitch.com ) is free for students, that's why I mention it, but I'm not sure if it is still available. LeapFTP (
http://www.leapware.com ) is shareware but an excellent FTP client. Another free one is CoffeeCup Free FTP 2.0 (
http://www.tucows.com/preview/195147.html ). There are others on Tucows:
http://tucows.tierra.net/ftp95_default.html
yes!
Posted: Wed Jan 07, 2004 4:35 pm
by webwasp
Leap FTP enabled me to change the read write permissions of the test file!!!
Why bother with the big powerful (expensive) Dreamweaver??
Thanks ever so much for all the help.
I run a Flash Tutorial site:
http://www.webwasp.co.uk so if you ever need any help with Flash – I’m your geek – cheers

Re: yes!
Posted: Wed Jan 07, 2004 5:12 pm
by scorphus
Good, I'm glad it works! I also never ever liked Dreamweaver - I'm a Linux user. I'm _very_ happy with Zend Studio.
Nice Flash site, I like tutorials site. I run a Blender tutorial site (
http://scorphus.no-ip.com ). I'm not that good in Flash

(just some actionscripts here and there).
Well, thanks for offering your help!
See ya,
Scorphus.