Wouldn't
code:
<?php
$filename = "count.txt";
$x = file_get_contents("$filename");
$x = $x+1;
file_put_contents("$filename", $x);
echo $x;
?>
be simpler?
Or, if there's a PHP equivalent of C's scanf, use that to read the number from the file, and a printf equivalent to write it.