0

how to determine which country the IP is coming from ? like e.g when a visitor came to a site, I can log the ip using

$_SERVER['REMOTE_ADDR'] , 

but that's all a combination of numbers, if let's say I want to log only the IP address coming from the US,AU,UK, or any other country that I want specifically, how to do that "without" using any database tables where the logger is hosted ?

sasori
  • 5,249
  • 16
  • 86
  • 138
  • see http://stackoverflow.com/questions/2468199/get-country-location-of-an-ip-with-native-php – Tim Feb 02 '12 at 10:58
  • Try to google for `ip country`, you'll come up with results like this http://www.maxmind.com/app/geoip_country – Vyktor Feb 02 '12 at 10:59
  • You "have" to use some kind of database to lookup the IP address against list of countries. – Salman A Feb 02 '12 at 10:59
  • You have to use a lookup API like [`ipinfodb.com`](http://ipinfodb.com/ip_location_api.php). There is no mathematical order to the geo-location of IP addresses, the only solution is to use a lookup table, be that one you host your self or somebody else's. – DaveRandom Feb 02 '12 at 11:00

3 Answers3

3

A nice web service for this is http://www.whoisxmlapi.com/.

You can get the data as XML or JSON and use the country attribute of the header.

tbraun89
  • 2,246
  • 3
  • 25
  • 44
1

You can use the IP to country mappings provided by Webnet77. The database contains about 100000 entries for various IPv4 blocks and can be downloaded in CSV format. You can later include that CSV in your logger script to find a country.

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
0

Look into using a geoip location service like Maxmind

René Höhle
  • 26,716
  • 22
  • 73
  • 82
Barry Chapman
  • 6,690
  • 3
  • 36
  • 64