Я использовал следующие функции в моем приложении: http://ipaddress.standingtech.com/ исключить CloudFlare IP address
<?php
/*
* @param $ips = array of IP address
*/
function clear_flare_ips($ips){
foreach($ips as $index => $ip){
if(is_in_flareips($ip)){
unset($ips[$index]);
}
}
ksort($ips);
return $ips;
}
function is_in_flareips($ip){
$flareips = getflareips();
foreach($flareips as $range){
if(ip_in_range($ip, $range)){
return true;
}
}
return false;
}
function getallips(){
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress[] = $_SERVER['HTTP_CLIENT_IP'];
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress[] = $_SERVER['HTTP_X_FORWARDED'];
if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress[] = $_SERVER['HTTP_FORWARDED_FOR'];
if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress[] = $_SERVER['HTTP_FORWARDED'];
if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress[] = $_SERVER['REMOTE_ADDR'];
if(count($ipaddress) == 0)
$ipaddress[] = 'UNKNOWN';
return $ipaddress;
}
function getflareips(){
/*
https://www.cloudflare.com/ips-v4
*/
return array(
'103.21.244.0/22',
'103.22.200.0/22',
'103.31.4.0/22',
'104.16.0.0/12',
'108.162.192.0/18',
'131.0.72.0/22',
'141.101.64.0/18',
'162.158.0.0/15',
'172.64.0.0/13',
'173.245.48.0/20',
'188.114.96.0/20',
'190.93.240.0/20',
'197.234.240.0/22',
'198.41.128.0/17',
'199.27.128.0/21'
);
}
function ip_in_range($ip, $range) {
/**
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
* @return boolean true if the ip is in this range/false if not.
*/
if (strpos($range, '/') == false) {
$range .= '/32';
}
// $range is in IP/CIDR format eg 127.0.0.1/24
list($range, $netmask) = explode('/', $range, 2);
$range_decimal = ip2long($range);
$ip_decimal = ip2long($ip);
$wildcard_decimal = pow(2, (32 - $netmask)) - 1;
$netmask_decimal = ~ $wildcard_decimal;
return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
}
Посмотрите на это http://www.phpf1.com/tutorial/get-ip-address.html –
Если бы вы могли проверить ниже? все еще найдено havent – Jeroen