We have 28 guests online
PHP Scripts arrow Free PHP Tutorials arrow Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP 
Free PHP Tutorials arrow PHP Tutorials and Examples arrow PHP

Hit Counter
User Rating: / 7
PoorBest 

A simple hit counter using a file

  1. <?php
  2. /*
  3. Name: Brkwtzandrew
  4. Site: http://brkwtzandrew.nfshost.com
  5. Script: Counter Script
  6. Description: A simple hit counter that uses a file to record the number of visitors.
  7. Last-edited: 1 January 2006
  8. Important: You need to create a file called hits.txt in the same directory where the script runs
  9. */
  10. $file = "hits.txt";
  11. // The file to open (you have to create it)
  12. $handle = fopen($file, "r");
  13. // open the file
  14. $hits = fread($handle, filesize("$file"));
  15. // assigns the content of the file to the number of hits
  16. fclose($handle);
  17. ++$hits;
  18. //add a hit for the current user
  19. $handle2 = fopen($file, "w+");
  20. fwrite($handle2,"$hits");
  21. // Add the current visit to the hits.
  22. fclose($handle2);
  23. echo "You have "."$hits"." visits";
  24. // Output number of hits.
  25. ?>

 

 

Directory Stats

There are 905 listing and 46 categories in our website

Change Language