Доброго дня! Есть вопрос к более опытным в php. У меня список диапазонов в txt Code: 2.63.128.0-2.63.255.255 5.22.153.0-5.22.153.255 5.44.168.0-5.44.175.255 5.128.0.0-5.129.191.255 5.130.0.0-5.131.255.255 5.137.0.0-5.137.255.255 31.133.104.0-31.133.111.255 31.173.248.0-31.173.248.255 31.173.249.24-31.173.249.31 31.173.250.0-31.173.251.255 31.173.253.0-31.173.255.255 31.184.236.0-31.184.236.255 37.29.80.0-37.29.87.255 37.49.192.0-37.49.223.255 37.192.0.0-37.195.255.255 37.205.48.0-37.205.55.255 37.205.64.0-37.205.95.255 46.29.192.64-46.29.192.71 46.29.192.96-46.29.192.127 46.29.192.144-46.29.192.159 46.29.192.192-46.29.193.63 46.29.193.80-46.29.194.191 46.29.194.208-46.29.199.255 46.50.132.128-46.50.132.129 46.50.132.255-46.50.132.255 46.50.133.128-46.50.133.255 46.50.135.0-46.50.135.1 46.50.135.127-46.50.135.127 46.50.140.0-46.50.143.255 46.50.146.0-46.50.147.255 46.50.150.128-46.50.152.1 46.50.152.127-46.50.152.255 46.50.154.0-46.50.155.255 Как можно прогнать $_SERVER['REMOTE_ADDR']; по этому списку на вхождение в дипазон
PHP: $ip2match = '5.44.170.22';$list = array('5.44.168.0-5.44.175.255');//$ip2match = $_SERVER['REMOTE_ADDR'];//$list = file('list.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);foreach($list as $range){ list($start, $end) = explode('-', $range); if(in_array(ip2long($ip), range(ip2long($start), ip2long($end)))) die('Match '.$ip.' in '.$range);}
Я пока твой пост не прочел запилил уже свое PHP: $file = file('redir/'.$redir.'/iplist.txt'); $len = count($file); for ($i=0; $i<$len; $i++) { //trim $ipx = explode('-', $file[$i]); $longip1 = ip2long(trim($ipx[0])); $longip2 = ip2long(trim($ipx[1])); $longip3 = ip2long(trim($ip)); if($longip3 >= $longip1 and $longip3 <= $longip2){ $detect = TRUE; }