Advertisement
michaelyuen

Untitled

Mar 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 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 vcount($count_file,$ip_file){
  11.     $ip = getRealUserIp();
  12.     $hit = (file_exists($count_file)) ? file_get_contents($count_file) : 0;
  13.     if (!in_array($ip, file($ip_file, FILE_IGNORE_NEW_LINES))){
  14.             file_put_contents($ip_file, $ip."\n", FILE_APPEND);
  15.             file_put_contents($count_file, ++$hit);
  16.     }
  17.     return $hit;
  18. }
  19.  
  20. $count_file = 'counter.txt';
  21. $ip_file = 'ip.txt';
  22.  
  23. if(!file_exists($count_file)){ fopen($count_file, 'w'); }
  24. if(!file_exists($ip_file)){ fopen($ip_file, 'w'); }
  25.  
  26. echo vcount($count_file,$ip_file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement