Тут интересно описано о проксировании
https://habr.com/ru/post/177113/
У нас в проекте получаем так:
function fn_get_ip($return_int = false)
{
$forwarded_ip = '';
$fields = array(
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_forwarded_ip',
'HTTP_X_COMING_FROM',
'HTTP_COMING_FROM',
'HTTP_CLIENT_IP',
'HTTP_VIA',
'HTTP_XROXY_CONNECTION',
'HTTP_PROXY_CONNECTION');
$matches = array();
foreach ($fields as $f) {
if (!empty($_SERVER[$f])) {
preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $_SERVER[$f], $matches);
if (!empty($matches) && !empty($matches[0]) && $matches[0] != $_SERVER['REMOTE_ADDR']) {
$forwarded_ip = $matches[0];
break;
}
}
}
$ip = array('host' => $forwarded_ip, 'proxy' => $_SERVER['REMOTE_ADDR']);
if ($return_int) {
foreach ($ip as $k => $_ip) {
$ip[$k] = empty($_ip) ? 0 : sprintf("%u", ip2long($_ip));
}
}
if (empty($ip['host']) || !fn_is_inet_ip($ip['host'], $return_int)) {
$ip['host'] = $ip['proxy'];
$ip['proxy'] = $return_int ? 0 : '';
}
return $ip;
}
function fn_is_inet_ip($ip, $is_int = false)
{
if ($is_int) {
$ip = long2ip($ip);
}
$_ip = explode('.', $ip);
return
($_ip[0] == 10 ||
($_ip[0] == 172 && $_ip[1] >= 16 && $_ip[1] <= 31) ||
($_ip[0] == 192 && $_ip[1] == 168) ||
($_ip[0] == 127 && $_ip[1] == 0 && $_ip[2] == 0 && $_ip[3] == 1) ||
($_ip[0] == 255 && $_ip[1] == 255 && $_ip[2] == 255 && $_ip[3] == 255))
? false : true;
}