Basic Hit Counter In PHP

A very basic hit counter in PHP; it uses a text file to store the number of hits and displays the number of current hits.

if (gethostbyaddr($_SERVER['REMOTE_ADDR']))
{
   $CntFile = "HitCounter.txt";
   $Hits = file($CntFile);
   $CurrHits = $Hits[0]++;
   $FileHandle= fopen($CntFile, "w"); // Open as a writable file
   fputs($FileHandle, $CurrHits);
   fclose($FileHandle);
   echo "Hits: ".number_format($CurrHits);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top