Reputation: 18379
I want to identify the country my visitors come from using php. How can I do this?
Upvotes: 3
Views: 3865
Reputation: 1
You can find more details about How to find the city and country of the visitor using PHP in this blog - http://virallangaliya.blogspot.in/2013/04/how-to-find-city-and-country-of-visitor.html
Upvotes: 0
Reputation: 25471
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.
Upvotes: 1
Reputation:
There is a complete project using the maximind API in PHP Where are you from? IP Geolocation
Upvotes: 0
Reputation: 61557
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
Upvotes: 10
Reputation: 4067
I recommend you taking a look at the MaxMind's GeoIP API:
http://www.maxmind.com/app/php
Upvotes: 1
Reputation: 176352
You need to use a Geolocation service/database. Check out the Maxmind API.
Upvotes: 1