0

I need an alternative way of grabbing country codes. Here's a script that uses geoip, see the func (geoip_record_by_name).

$ip = $_SERVER['REMOTE_ADDR'];
$record = geoip_record_by_name($ip);
$countryid = $record['country_code'];
$countryname = $record["country_name"];
$countryallowed = array("AL", "AM", "AR", "AT", "AU", "AX", "BA", "BD", "BE", "BG", "BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CZ", "DE", "DJ", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GE", "GF", "GL", "GR", "GY", "HK", "HR", "HU", "ID", "IE", "IL", "IN", "IR", "IS", "IT", "JO", "JP", "KH", "KP", "KR", "KZ", "LB", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "ML", "MN", "MW", "MX", "MY", "NL", "NO", "NR", "NZ", "PE", "PH", "PL", "PR", "PT", "PW", "PY", "RE", "RO", "RS", "RU", "SE", "SG", "SI", "SK", "SR", "TH", "TR", "TW", "UA", "US", "UY", "UZ", "VE", "VN", "YE", "ZA");
4

2 回答 2

0

您是否考虑过 hostip.info

于 2011-04-08T06:20:00.307 回答
-2

尝试使用 SOAP:http ://www.webservicex.net/geoipservice.asmx?op= GetGeoIP 您所要做的就是:

$url = 'http://www.webservicex.net/geoipservice.asmx/GetGeoIP?IPAddress=';
if ($stream = fopen(url.$_SERVER['REMOTE_ADDR'], 'r')) {
    $soapResponse = stream_get_contents($stream, 1024);
    fclose($stream);
}

$xml = simplexml_load_string($soapResponse);

echo $xml->CountryCode; 

注意:我不知道有多少请求是免费的(每天,每个请求 IP - 您的服务器,或全部)。

于 2011-04-08T06:44:01.230 回答