0

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
halfer
  • 19,824
  • 17
  • 99
  • 186
user1768788
  • 1,265
  • 1
  • 10
  • 29

2 Answers2

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.

Oswald
  • 31,254
  • 3
  • 43
  • 68
1

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 
Baba
  • 94,024
  • 28
  • 166
  • 217