help with a .txt hit counter using php

Status
Not open for further replies.

Citizen66

Beta member
Messages
1
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:
<?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:
<?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?
 
Status
Not open for further replies.
Back
Top Bottom