Forum Moderators: coopster

Message Too Old, No Replies

Php counter problem

permission denied error message

         

windranger

1:15 pm on May 12, 2007 (gmt 0)

10+ Year Member



Hi,

Whenever I access the php counter of my site I get some nasty errors, as below:

Warning: fopen(/home/romaniap/domains/.../public_html/phpmycounter/counter.dat) [function.fopen]: failed to open stream: Permission denied in /.../public_html/phpmycounter/counter.php on line 24

Warning: fputs(): supplied argument is not a valid stream resource in /.../public_html/phpmycounter/counter.php on line 25

Warning: fclose(): supplied argument is not a valid stream resource in /.../public_html/phpmycounter/counter.php on line 26

Now, this happens even after I set permission to 755 for all the files in the counter's folder and also for the folder.

(the 24, 25, 26th lines in "counter.php", to which errors reffer, are like this:
$fp = fopen($CONFIG['counter_data'], "w");
fputs ($fp, $count);
fclose ($fp);
)

It's strange, because the counter worked well before..

I just can't track the bug.... somebody any ideas..?

Thanx

Birdman

1:58 pm on May 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



755 is not enough permissions because PHP runs as user "nobody" or "99" or similar. This means that it will not have write perms.

You could chmod 777 (very BAD)

or you could change the owner of the folder to 99:99 (requires root priveledges)

Getting root privs may not be possible so what I do in this case is:

1) Create a PHP script that will simply create the directory.

<?php
mkdir("counter", 0755);
?>

2) place this script on your server and then set the permissions of the folder that this file resides in to 777 (only temporarily!)
Example: place the file in /public_html, set public_html to 777, run the script then reset public_html to it's normal settings. You will now have /public_html/counter/ and it will be owned by 99!

Now PHP will be able to write to that folder with only 755 permissions.

Give it a go! It works.

[edited by: Birdman at 1:59 pm (utc) on May 12, 2007]