问题
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