/** * nv_getCountry_from_file() * * @param string $ip * @return */ function nv_getCountry_from_file($ip) { global $countries; if (preg_match('#^(?:(?:\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$#', $ip)) { $numbers = preg_split("/\\./", $ip); $code = $numbers[0] * 16777216 + $numbers[1] * 65536 + $numbers[2] * 256 + $numbers[3]; $ranges = array(); include NV_ROOTDIR . '/' . NV_DATADIR . '/ip_files/' . $numbers[0] . '.php'; if (!empty($ranges)) { foreach ($ranges as $key => $value) { if ($key <= $code and $value[0] >= $code) { return $value[1]; } } } return nv_getCountry($ip); } else { return "ZZ"; } }
/** * nv_getCountry_from_file() * * @param mixed $ip * @return */ function nv_getCountry_from_file($ip) { $numbers = preg_split("/\\./", $ip); $ranges = $countries = array(); $two_letter_country_code = $three_letter_country_code = $country_name = ""; include NV_ROOTDIR . "/includes/ip_files/" . $numbers[0] . ".php"; $code = $numbers[0] * 16777216 + $numbers[1] * 65536 + $numbers[2] * 256 + $numbers[3]; if (!empty($ranges)) { foreach ($ranges as $key => $value) { if ($key <= $code) { if ($ranges[$key][0] >= $code) { $two_letter_country_code = $ranges[$key][1]; break; } } } } if ($two_letter_country_code == "") { return nv_getCountry($ip); } else { include NV_ROOTDIR . "/includes/ip_files/countries.php"; $three_letter_country_code = $countries[$two_letter_country_code][0]; $country_name = $countries[$two_letter_country_code][1]; } return array($two_letter_country_code, $three_letter_country_code, $country_name); }