Hey guys, this is my first post.
I'm having problems with a flat-file unique hits counter which I found online at in obscuro.

I installed everything properly, but whenever I try going to the "showcounter.php" file to display the total amount of hits I have received, the page freezes up and I get an error_log in my folder which displays this:

PHP Warning:  fread(): supplied argument is not a valid stream resource in /directory/showcounter.php on line 12
PHP Warning:  feof(): supplied argument is not a valid stream resource in /directory/showcounter.php on line 11

Now, I do not believe that I am allowed to post the code used, but in the link above I linked to the tutorial which I got the code from. The link is legit and you don't have to download anything, I promise.

Thank you in advance!

Recommended Answers

All 10 Replies

As far as I could see, there does not exist a counter folder in which a count.db exists. So create a folder named "counter" and create a file in that named "count.db"


Member Avatar

May be permission issues on your folder.

Thank you for the responses guys but...

I had a counter folder; I just removed it from the error lines because the directory was too long. The permissions for the folder is set to 755.
Also, the only files which were chmoded were ip.db and counter.db (to 666).

Each file works except for the showcounter.php file. Should I change the permissions?

Member Avatar

data folder should be set to 0777 and it is and the files inside should be 0666

Setting the folder to 0777 and the files inside to 0666 causes a hiccup on the server, so it automatically rewrites them back to their original settings.

Member Avatar

To grant a PHP write permissions in a directory owned by you, the only option you have is to set the directory's permissions to 0777 (world-writeable).

rajarajan was right... it's all about file permission. You must edit it either through ftp or explicitly define it using php chmod() function. set the permission to 0775

Well, I have been trying your solution rajarajan07, but my server keeps changing the permissions to something "safer".

Is there any way I can bypass this?

Also tried that, it didn't work.

I think I give up on this; after researching it seems that my host doesn't allow anything higher than a 755.

php scripts run with super user privledges, so chmod 755 is effecitvely the same as 777

It's not working with a 0755 though and it keeps rewriting my files from 0666 to 0644, so I think my host is to blame here.

Thanks guys for your responses and time, I really appreciate it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.