PHP : Performing IP Geolocation

One of the questions that i commonly see in suppport foums or in PHP newsgroups is how to identify what country a user resides in. Although the server where PHP is located could be anywhere in the world and the user could be located anywhere in the world,it is possible to make a geographic match.

Every computer must have an IP address to have Internet access(or to connect to any network). An Internet service provider(ISP) assign a computer an IP address from a pool of valid address only they have access to. By knowing a computer's IP address, which PHP puts in $_SERVER['REMOTE_ADDR'], one can know the ISP and thereform, the country. Hence the name IP geolocation. New GeoIP databases can even predict the city and state although with less accuracy.

To Learn more about IP Geolocation, download source code and databases , online demos , please visit http://www.maxmind.com site.


One resource I found suggested that IP geolocation is very accurate on the country level, probably close to 95 percent. On the city and State level, that accuracy may dip down to 50-80 percent, depending upon the database being used.Use commercial database instead of Free/Open Source to get more accurate results.