Advertisement
touhid_xml

Make Page hits using file function

Jan 28th, 2013
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function set_count($file = 'counter.txt'){
  3.  
  4. if(file_exists($file)){
  5.  
  6.   //read the value of the file
  7. $handle= fopen($file, 'r');
  8.  
  9. //increase it by one
  10. $count = (int) fread($handle, 20) + 1;
  11.  
  12. //write the value in file
  13. $handle= fopen($file, 'w');
  14. fwrite($handle, $count);
  15. fclose($handle);
  16.  
  17. }
  18. else{
  19. //creat it
  20.   $handle = fopen($file, 'w+');
  21.  
  22.   //set the defualt value 1
  23.   fwrite($handle, 1);
  24.   fclose($handle);
  25.  
  26. $count= 1;
  27. }
  28. return $count;
  29. }
  30.  
  31. echo set_count();
  32.  
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement