Geolocate an IP without extensions?

大城市里の小女人 提交于 2019-12-10 12:20:30

问题


Is there a way to locate an IP's country without using any php extensions?

I know there are certain extensions, but is this possible without using extensions nor using other websites. For example:

www.[ip to country].[something]/?ip=123.123.123.123

回答1:


Download a database that maps IP addresses to countries, e.g. from MaxMind, and install it on the server.

There is no way to calculate the information stored in the database without accessing remote systems. That's why you really need a database for that.




回答2:


You can use

$url = "http://www.geoplugin.net/json.gp?ip=173.194.41.103";
$json = json_decode(file_get_contents($url));
printf("%s,%s", $json->geoplugin_regionName, $json->geoplugin_countryName);

Output

California,United States 


来源:https://stackoverflow.com/questions/16385264/geolocate-an-ip-without-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!