What are the location detecting techniques for IP addresses?
I know to look at the
$_SERVER[\'HTTP_ACCEPT_LANGUAGE\']
(not accurate but mostly useful to
U can use this function
function ip_info(){
return $data = json_decode(file_get_contents('http://ip-api.com/json/'),true);
}
Call the function
$info = ip_info();
var_dump($info);
Instead of using third party API I would suggest you to use self hosted IP record. This post explain you more
http://www.techsirius.com/2014/05/simple-geo-tracking-system.html
Basically they are using maxmind's country city IP database record [http://dev.maxmind.com/geoip/geoip2/geolite2/] with few modifications. After that a sample query
$ip = $_SERVER['REMOTE_ADDR'];
$long = sprintf('%u', ip2long($ip));
$sql = "SELECT * FROM `geo_ips` WHERE '$long' BETWEEN `ip_start` AND `ip_end`";
One way in which these databases are compiled is from whois information. For example, to determine the location of 69.59.196.211:
fmark@home:~$ host 69.59.196.211 211.196.59.69.in-addr.arpa domain name pointer stackoverflow.com. fmark@home:~$ whois stackoverflow.com
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered with many different competing registrars.
<SNIP>
> Registrant: stackoverflow.com llc
410 Clayton Ave El Cerrito, California 94530 United States<SNIP>
Obviously this isn't hugely accurate, so more sophisticated techniques are allegedly used.