A Reeeeaaly simple Hit counter

ReDuX ReDuX is offline Offline Oct 23rd, 2004, 3:51 am |
0
Ok, this is about as simple as it gets. This is a hit counter for your page that stores the count in a simple text file of your choosing. No need for a database, MySQL or otherwise. No complicated rubbish. Just one single function and one single file to store the count. Thats it.
Quick reply to this message  
PHP Syntax
  1. <?php
  2. /* first you will need to create a text file somewhere and give it
  3. a name obviously. In this example I will call it hits.txt */
  4. $stored = "hits.txt";
  5.  
  6. /* The following function when called gets the text file
  7. named in the above variable '$stored', then opens it for
  8. reading and writing, saves its contents in variable $stuff
  9. closes it, then opens it again, adds 1 to $stuff,
  10. displays $stuff and then saves and closes the file again. */
  11.  
  12. function displayHitThingy($stored) {
  13. $fp = fopen($stored,rw);
  14. $stuff = fgets($fp,9999);
  15. fclose($fp);
  16. $fp = fopen($stored,w);
  17. $stuff += 1;
  18. print "$stuff";
  19. fputs($fp, $stuff);
  20. fclose($fp);
  21. }
  22.  
  23. /* Now you just display it on your page somewhere
  24. with the following */
  25. ?>
  26. Page hits: <?php displayHitThingy($stored); ?>
  27. <?php
  28. /* Thats it. You can of course use it on more than one
  29. page, just remember to change the textfiles name for each
  30. e.g. page1.txt page2.txt and so on.. */
  31. ?>
0
Alona Alona is offline Offline | Nov 3rd, 2005
how is this simple

isnt there a program to downlad posibly


reese
 
0
DaveSW DaveSW is offline Offline | Nov 4th, 2005
Reese
This script requires PHP support on your server to work.
If you have PHP enabled, you copy and paste the script above into the page where you want it.
You will probably need to be in 'code view' or whatever the equivalent is in the software you are using.
You then have to rename the script to have a .php extension instead of a .htm or .html
Be aware that any other links to this page will need to be updated to reflect the name change.
Hope this helps you out
Dave
 
 

Message:


Similar Threads
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC