来自php的国家名称
如何使用Php从Ip地址获取国家名称,而不使用商业GeoIP区域版本。请问有人帮我吗 我不认为您可以简单地使用PHP来实现,但我已经找到了一个免费的API解决方案,您可以使用它。它需要简单的帖子和回复。 示例帖子: 答复示例: 国家:美国 城市:伊利诺伊州糖林使用代码来自php的国家名称,php,ip-address,Php,Ip Address,如何使用Php从Ip地址获取国家名称,而不使用商业GeoIP区域版本。请问有人帮我吗 我不认为您可以简单地使用PHP来实现,但我已经找到了一个免费的API解决方案,您可以使用它。它需要简单的帖子和回复。 示例帖子: 答复示例: 国家:美国 城市:伊利诺伊州糖林使用代码 $json = file_get_contents('http://freegeoip.appspot.com/json/66.102.13.106'); $expression = json_decode($json); p
$json = file_get_contents('http://freegeoip.appspot.com/json/66.102.13.106');
$expression = json_decode($json);
print_r($expression);
结果
stdClass Object
(
[status] => 1
[ip] => 66.102.13.106
[countrycode] => US
[countryname] => United States
[regioncode] => CA
[regionname] => California
[city] => Mountain View
[zipcode] => 94043
[latitude] => 37.4192
[longitude] => -122.057
)
United States
得名
echo $expression->countryname;
结果
stdClass Object
(
[status] => 1
[ip] => 66.102.13.106
[countrycode] => US
[countryname] => United States
[regioncode] => CA
[regionname] => California
[city] => Mountain View
[zipcode] => 94043
[latitude] => 37.4192
[longitude] => -122.057
)
United States
如果您想安装自己的应用程序,这里是上述解决方案的git源代码,作者:Peter(我总是更喜欢自托管解决方案,而不是点击并依赖其他服务):
没有商业API或根本没有GeoIP API?假设您有仅从PHP>=5.2提供的
json\u decode()
。它只在美国有效吗?我没有收到任何来自德国的有效回复。