| 1 |
<?php |
| 2 |
if (! (defined('ABSPATH') || defined('MCDATAPATH')) ) exit; |
| 3 |
if (!class_exists('BVProtectBase')) : |
| 4 |
|
| 5 |
class BVProtectBase { |
| 6 |
public static function getIP($ipHeader) { |
| 7 |
$ip = '127.0.0.1'; |
| 8 |
if ($ipHeader && is_array($ipHeader)) { |
| 9 |
if (array_key_exists($ipHeader['hdr'], $_SERVER)) { |
| 10 |
$_ips = preg_split("/(,| |\t)/", $_SERVER[$ipHeader['hdr']]); |
| 11 |
if (array_key_exists(intval($ipHeader['pos']), $_ips)) { |
| 12 |
$ip = $_ips[intval($ipHeader['pos'])]; |
| 13 |
} |
| 14 |
} |
| 15 |
} else if (array_key_exists('REMOTE_ADDR', $_SERVER)) { |
| 16 |
$ip = $_SERVER['REMOTE_ADDR']; |
| 17 |
} |
| 18 |
|
| 19 |
$ip = trim($ip); |
| 20 |
if (preg_match('/^\[([0-9a-fA-F:]+)\](:[0-9]+)$/', $ip, $matches)) { |
| 21 |
$ip = $matches[1]; |
| 22 |
} elseif (preg_match('/^([0-9.]+)(:[0-9]+)$/', $ip, $matches)) { |
| 23 |
$ip = $matches[1]; |
| 24 |
} |
| 25 |
|
| 26 |
return $ip; |
| 27 |
} |
| 28 |
} |
| 29 |
endif; |