I want to know how to implement Location Based service in my website where i can find the exact location of the user who is accessing my site.. I tried with $_SERVER['REMOTE_ADDR'], but its giving ISP IP .. which is开发者_运维百科 a bit inaccurate..
Thanks in Advance.
I recently implemented geolocation with GeoIP (a PEAR package). It is not terribly accurate, but it gives country ok, region/state ok and major nearest city almost always right.
Once you install the package, you have to download the latest data file from maxmind, and it can be as easy to use as this:
require_once "Net/GeoIP.php";
$geoloc = Net_GeoIP::getInstance('/var/www/GeoIP.dat');
try{
$countryCode = $geoloc->lookupCountryCode($_SERVER['REMOTE_ADDR']);
}
catch(Exception $e) {}
精彩评论