To expand on TheDefender's idea, you could write a function that is more flexible in working with different counter files, and which has better error checking, e.g.
function updateCounter($filename) {
//read contents of file $filename into $num
if (($num = file_get_contents($filename)) !== false) {
$num++; //increment current count
if (($fp = fopen($filename, "wb")) !== false) {
//store new count
if (fwrite($fp, $num) !== false) {
fclose($fp);
return $num; //new count value
} else {
fclose($fp);
return false;
}
} else {
return false;
}
} else {
return false;
}
}
To use it, you might do a:
if (($count = updateCount("/path/to/file.txt")) !== false) {
echo "Current count is " . $count;
} else {
echo "Error: could not retrieve current count";
}