::PHP::

simple web counter
comments:
this is a really simple counter that writes to a text file ("counter.txt"), opens it and reads the value saved there. the value is then incremented and the file is resaved.
the value can be reset possibly by two write attempts happening at the same time (?) or the writing was aborted in mid-write. something of that nature. i'm not
sure how to safeguard against these events quite yet.

code:
$filename = "counter.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);

$count = $contents + 1;

$handle2 = fopen($filename, 'w');
fwrite($handle2, $count);
fclose ($handle2);

echo "counter: " . '<b>' . "$count" . '</b>';
echo '<br>';