kaed

unique hit counter p2

May 19th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2.     $filename = 'counter.txt';
  3.     $ip_filename = 'ip.txt';
  4.    
  5.     function inc_count() {
  6.         $ip = $_SERVER['REMOTE_ADDR'];
  7.         global $filename, $ip_filename;
  8.        
  9.         if(!in_array($ip, file($ip_filename, FILE_IGNORE_NEW_LINES))) {
  10.             $current_value = (file_exists($filename)) ? file_get_contents($filename) : 0 ;
  11.             file_put_contents($ip_filename, $ip."\n", FILE_APPEND);
  12.             file_put_contents($filename, ++$current_value);
  13.         }
  14.     }
  15.    
  16.     inc_count();
  17.    
  18. ?>
Add Comment
Please, Sign In to add comment