Well I tested your code out and nothing appears to be wrong with it, thou I would suggest a slight clean-up of the if statement by using an else afterwards, since you've already established that the counter must be equal to 1, that and the second section would end up adding 1 to the total so the start value would in escence be 2.
<?php
$counterdir = "/home/tc/counters/";
$filename = ($counterdir.ereg_replace("/", "!", $PHP_SELF).".counter");
if (!file_exists("$filename"))
{
$count = 1;
$file = fopen ($filename, "w+");
fputs ($file, $count);
fclose ($file);
}
else
{
$file = fopen ($filename, "r+");
$count = fread($file, filesize ($filename));
fclose ($file);
$count += 1;
$file = fopen ($filename, "w+");
fputs ($file, $count);
fclose ($file);
}
?>
Ummm silly question, but you're using a linux based system right? Have you made sure that php has read/write privliges to the "/home/tc/counters/" directory?