...

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



aktell
11-02-2006, 05: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)
#!/usr/local/bin/php

I useed this code for the counter"

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

Thanks in advance for any help. aktell

CFMaBiSmAd
11-03-2006, 03: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 -

error_reporting(E_ALL);

aktell
11-10-2006, 01: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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum