Advertisement
michaelyuen

Untitled

Mar 25th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. function getRealUserIp(){
  2.     switch(true){
  3.       case (!empty($_SERVER['HTTP_X_REAL_IP'])) : return $_SERVER['HTTP_X_REAL_IP'];
  4.       case (!empty($_SERVER['HTTP_CLIENT_IP'])) : return $_SERVER['HTTP_CLIENT_IP'];
  5.       case (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) : return $_SERVER['HTTP_X_FORWARDED_FOR'];
  6.       default : return $_SERVER['REMOTE_ADDR'];
  7.     }
  8.  }
  9.  
  10. function count($count_file, ip_file){
  11.     $ip = getRealUserIp();
  12.    
  13.     if(!in_array($ip, file($ip_file, FILE_IGNORE_NEW_LINES))){
  14.             $hit = (file_exists($count_file)) ? file_get_contents($count_file) : 0;
  15.             file_put_contents($ip_file, $ip."\n", FILE_APPEND);
  16.             file_put_contents($count_file, ++$hit);
  17.             return $hit;
  18.     }
  19. }
  20.  
  21. if(!file_exists($count_file)){ fopen($count_file, 'w'); }
  22. if(!file_exists($ip_file)){ fopen($ip_file, 'w'); }
  23.  
  24. echo count('counter.txt','ip.txt');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement