Geekpedia Programming Tutorials






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.

On Friday, October 17th 2008 at 01:11 PM
By Andrew Pociu (View Profile)
-----   (Rated 0 with 0 votes)
Contextual Ads
More PHP Resources
Advertisement
  1. if (gethostbyaddr($_SERVER['REMOTE_ADDR']))
  2. {
  3.    $CntFile = "HitCounter.txt";
  4.    $Hits = file($CntFile);
  5.    $CurrHits = $Hits[0]++;
  6.    $FileHandle= fopen($CntFile, "w"); // Open as a writable file
  7.    fputs($FileHandle, $CurrHits);
  8.    fclose($FileHandle);
  9.    echo "Hits: ".number_format($CurrHits);
  10. }
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
There are no comments.

Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs PHP Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons