Forum Moderators: DixonJones
Create a blank text file (in notepad) and called it counter.txt and put " 0 " in it then chmod it to 777.
Put this code on your page:
php
$fp = fopen("counter.txt","r");
$count = fread ($fp, filesize ("counter.txt"));
fclose($fp);
$count++;
$fp = fopen("counter.txt","a+");
fputs($fp, $count);
fclose($fp);
echo "Hits: $count";
?>
... but I don't know how to "chmod to 777". I know this is some sort of Unix command but I am just FTPing my files up to a shared server. Can I still use this script, and how do I get my notepad file there?
Alternatively I know I could also just go through my log files to see how many times the file is requested, but is there a way do get php to do this for me?
Any help would be much appreciated. Boss looks in a bad mood today.
Helen.
"chmod to 777" - why can't they just say, put it in the same directory? Cuh.
Not sure about the feasability of getting a script to read my log file - it's huge! Worried I might break the internet ;)
The counter is not running as well as I had hoped. It goes 1,2,13,1214,12131215 and I won't even tell you where it goes after that.
It's like one of those horrible which-number-is-next-in-the-sequence maths exam questions.
Also, the txt file seems to stay at 0 when I look at it.
I would like to get a script to read my logs, but I don't think I am putting the path right because it doesn't work. My logs are in a directory above the main public_html and I have put the path as
$fp = fopen("/home/mydomain/logs/access_log", "r");
but this doesn't seem to work.
Any thoughts?
cd /home/mydomain/logs
you get to the correct directory? I'd think that should work. In my case, the filename isn't just access_log, it has extensions to describe the date, e.g.
access.log.13.5
Are you sure yours is just "access_log"?
I read out my logs using php all the time (it's kind of addictive :-)
Rob