SHARE
TWEET

Untitled

a guest Jan 28th, 2020 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function get_ip_address() {
  2.     if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
  3.         return $_SERVER['HTTP_CLIENT_IP'];
  4.     }
  5.     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  6.         if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
  7.             $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  8.             foreach ($iplist as $ip) {
  9.                 if (validate_ip($ip))
  10.                     return $ip;
  11.             }
  12.         } else {
  13.             if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']))
  14.                 return $_SERVER['HTTP_X_FORWARDED_FOR'];
  15.         }
  16.     }
  17.     if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED']))
  18.         return $_SERVER['HTTP_X_FORWARDED'];
  19.     if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
  20.         return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
  21.     if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
  22.         return $_SERVER['HTTP_FORWARDED_FOR'];
  23.     if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED']))
  24.         return $_SERVER['HTTP_FORWARDED'];
  25.     return $_SERVER['REMOTE_ADDR'];
  26. }
  27. function validate_ip($ip) {
  28.     if (strtolower($ip) === 'unknown')
  29.         return false;
  30.     $ip = ip2long($ip);
  31.     if ($ip !== false && $ip !== -1) {
  32.         $ip = sprintf('%u', $ip);
  33.         if ($ip >= 0 && $ip <= 50331647) return false;
  34.         if ($ip >= 167772160 && $ip <= 184549375) return false;
  35.         if ($ip >= 2130706432 && $ip <= 2147483647) return false;
  36.         if ($ip >= 2851995648 && $ip <= 2852061183) return false;
  37.         if ($ip >= 2886729728 && $ip <= 2887778303) return false;
  38.         if ($ip >= 3221225984 && $ip <= 3221226239) return false;
  39.         if ($ip >= 3232235520 && $ip <= 3232301055) return false;
  40.         if ($ip >= 4294967040) return false;
  41.     }
  42.     return true;
  43. }
  44.  
  45. $_SERVER["REMOTE_ADDR"] = get_ip_address();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top