I'm trying to get hit counters displayed on a page counting pages elsewhere using a .txt file and I can't get the code to work.
On the page being counted:
PHP Code:
<?php
$myFile = "../../clicks/diana.txt";
$fp = fopen($myFile, 'r+');
$theData = fread($fp, filesize($myFile));
if(!$theData){
$theData = 0;
}else{
$theData++;
fseek($fp, 0, 0);
}
fwrite($fp, $theData);
fclose($fp);
?>
On the page showing the count:
PHP Code:
<?php
$myFile = "./clicks/diana.txt";
$fp = fopen($myFile, 'r');
$theData = fread($fp, filesize($myFile));
fclose($fp);
echo $theData;
?>
Any ideas where I'm going wrong?