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);  
}

Related Posts

3 Responses to “Basic Hit Counter In PHP”

  1. vintairee  on July 8th, 2009

    http://extjs.com/forum/member.php?u=79374 guitar lessons

  2. forexBroky  on July 20th, 2009

    You’re website looks very good, it was a pleasure to be on you’re. Keep on the good work

  3. ForexBroky  on July 25th, 2009

    I used this site to get information for that i had in my class. This is an excellent site for this information


Leave a Reply