I am just trying to make a very simple hit counter. I want to open the file "counter.txt", get the number in there, increment it, print it to screen, then write it back to the file. Here is the code I am trying to get to work.
<?php
$file = fopen("counter.txt", "w+");
$data = fgets($file, 100);
$data = $data + 1;
print("<p class='center'>$data</p>");
fputs($file, "$data");
fclose($file);
?>
It will open the file, read the "0" in there, increment it, print a "1", and write it back to the file, but it won't go to "2" if I refresh. Why not?