Hit counter PHP/iiS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Hit counter PHP/iiS

Post 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
mwong
Forum Commoner
Posts: 34
Joined: Sun Dec 28, 2003 2:58 am

Post 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?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Try changing fopen($counter_file, "r") to fopen($counter_file, "rb")... that might help.
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post 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...
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post 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!
Post Reply