views:

196

answers:

5

I want to identify the country my visitors come from using php. How can I do this?

+1  A: 

You need to use a Geolocation service/database. Check out the Maxmind API.

Simone Carletti
+1  A: 

Hi, I recommend you taking a look at the MaxMind's GeoIP API:

http://www.maxmind.com/app/php

Nathan
+9  A: 

You need to use the PHP GeoIP extension that allows you to locate various information about the users via IP. http://us.php.net/geoip

or you can use Maxmind's API to access the data aswell. http://www.maxmind.com/app/php

Chacha102
A: 

There is a complete project using the maximind API in PHP Where are you from? IP Geolocation

mikej
+1  A: 

I realise this is an old question but just in case people are still looking at it, be aware that the accuracy of these utilities is not guaranteed and you should be cautious what you use them for, especially if you start using them for lower granularity than country level searches.

WhatIsMyIPAddress.com claim 95-99% for country level but suggest 50-80% for city level in the USA (see http://whatismyipaddress.com/geolocation-accuracy). My experience is that some countries have an even lower accuracy rate for city level locations.

Edited: Not sure what the vote down is for - if there is something incorrect here please let us know. I am not aware of any current IP to Geo location techniques that allow city level accuracy reliably.

Mick