Location detecting techniques for IP addresses

前端 未结 9 1181
甜味超标
甜味超标 2020-11-28 12:22

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

9条回答
  •  隐瞒了意图╮
    2020-11-28 12:42

    If the geolocation functionality is not a big requirement for your project, you can use something as simple as this:

    $geotxt='';
    $dt=json_decode(@file_get_contents('https://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']));
    if ($dt!=null) $geotxt=$dt->country_name.', '.$dt->region_name.', '.$dt->city;
    echo $geotxt;
    

    You have to take into account that freegeoip has a limit of 10k request/hour.

提交回复
热议问题