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. The premise is this:
Every computer must have an IP address to have Internet access (or to connect to any network). An Internet service provider (ISP) assigns a computer an IP address from a pool of valid addresses 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 therefore, the country. Hence, the name IP geolocation. New GeoIP databases can even predict the city and state, although with less accuracy. The easiest way to implement this is to use the PEAR Net_Geo class. It uses online services to retrieve the information for a provided IP address. This class has its downsides, unfortunately the online resources used by the Net_Geo PEAR class aren’t that up-to-date, so its accuracy could fade over time. In the interest of most readily demonstrating the IP geolocation concept, I think it’s a fine enough option. A more accurate option is to use the Net_GeoIP PEAR class. Unfortunately, this is still in beta form at the time of this writing and relies upon a commercial database for best accuracy and information. In fact, as a rule of thumb, if you’re writing an application that relies upon IP geolocation, you’ll want to pay someone for a commercial database, which is likely to be most accurate.
- Kiran's blog
- 353 reads













Post new comment