basic hit counter


/ Published in: PHP
Save to your folder(s)

http://www.tutorialized.com/tutorial/Simple-Text-based-counter/374


Copy this code and paste it in your HTML
  1. <?php
  2. //tutorial for text-file based counter
  3. $counthandle=fopen("visits2.txt","r");
  4. //opens file for reading and writing
  5. $getcurrent=fread($counthandle,filesize("visits2.txt"));
  6. //reads in current value
  7. $getcurrent=$getcurrent+1;
  8. //increment count by 1
  9. fclose($counthandle);
  10. $counthandle1=fopen("visits2.txt","w");
  11. fputs($counthandle1,$getcurrent);
  12. //input new value
  13. fclose($counthandle1);
  14. $counthandle2=fopen("visits2.txt","r");
  15. $getrecent=fread($counthandle2,filesize("visits2.txt"));
  16. //gets new value
  17. //print "$getrecent";
  18. //print counter value
  19. fclose($counthandle2);
  20. ?>

URL: http://www.tutorialized.com/tutorial/Simple-Text-based-counter/374

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.