Page 1 of 1

Hit counter PHP/iiS

Posted: Sun Dec 28, 2003 8:42 pm
by Flash05
Help... I'm using PHP/iiS 5.1. My hit counter doesn't change value whenever I refresh the page...

Code:
<?php
//hit_counter1.php
$counter_file = "./count.dat";
if(!($fp = fopen($counter_file, "r"))) die ("Cannot open $counter_file.");
$counter = (int) fread($fp, 20);
fclose($fp);
$counter++;
echo "You're visitor No. $counter.";
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
?>

When i test this in IE, the result is still the same:
"You're visitor No. 1."

THanks... :D

Posted: Sun Dec 28, 2003 10:01 pm
by mwong
Is the .dat file updating?

Why do you have a "." and a "/" when you first declare the $counter_file variable? Did you mean to only put a "/" and accidently hit the "." key too?

Posted: Sun Dec 28, 2003 10:03 pm
by Gen-ik
Try changing fopen($counter_file, "r") to fopen($counter_file, "rb")... that might help.

Posted: Sun Dec 28, 2003 11:30 pm
by Flash05
tnx for the replies...

i already changed the counter.dat to counter.txt so that i would be easy to edit...

$counter_file = "count.txt";

i tried to put "2" in count.txt and save then refresh the page. The result was 3. but when i opened the file, the 2 there isn't changed though the script was able to read it but was not able to save it to 3. and when i keep on hitting the f5 key, it stays as "3"

i already tried the "rb" and the problem is still the same...

Posted: Mon Dec 29, 2003 1:46 am
by Flash05
is there a setting of some sort where it is not allowed to read/write in iiS? Im not sure if it is the problem though i thought of it coz the the file wasnt change during the course... the script only reads it and not change it... help... tnx!