View Full Version : Can't get counter code working !!!

11-02-2006, 06:30 AM
Hi there,

I'm very green again, three years ago I loved working with PhP and now the same as before I have to ask questions.
I just started a new web site again and wanted to use my so beloved PhP code. I can view web pages with php code but if I want to use code for a hit counter I get errors !!! I have used this code snippets hundrets of times but this time no luck.
My question is here really is if anybody could tell me if it is these days enough to just have the php code as below OR do I have to include anything else in a wepage ( I always had to use the following on the very top in my old .php pages)

I useed this code for the counter"

$counter = "counter_intro.txt";
function displayCounter($counter)
$fp = fopen("$counter", "r");
$num = fread( $fp, 100);
$fpsoma = ($num + 1);
$fa = fopen("$counter", "w");
fwrite( $fa, $fpsoma, 100);
echo "<font color=#00ff00><center>$fpsoma</center></font>";

Thanks in advance for any help. aktell

11-03-2006, 04:29 AM
Your first - #!/usr/local/bin/php - is unnecessary.

Your code works for me. If the .txt file does not initially exist, there would be an warning error output on the first fopen, but the file would be created by the second fopen. The code would then work thereafter.

If it is not working for you there is likely a permissions problem that is preventing PHP from performing the file functions. Add the following after your opening <?php tag to see what might be occurring -


11-10-2006, 02:31 AM
Hi there,

It's a while but only today I was able to return to this problem. It is still not working I have taken your advise and includet your code but it did not make a difference.
I have this site address to view for anybody to see what is reporting ???.

Thanks aktell