Php 带有JSON文件的IP

Php 带有JSON文件的IP,php,location,ip,php-7,Php,Location,Ip,Php 7,伙计们。我已经写了一小段代码来获取网站访问者的IP,因此我想问你我应该把$IP放在哪里才能获取当前位置 <?php $ip = $_SERVER['REMOTE_ADDR']; $details = json_decode(file_get_contents("https://freegeoip.net/json/{$ip}/github.com")); echo $details->city; ?> 只要使用“https://freegeoi

伙计们。我已经写了一小段代码来获取网站访问者的IP,因此我想问你我应该把
$IP
放在哪里才能获取当前位置

<?php
     $ip = $_SERVER['REMOTE_ADDR'];
     $details = json_decode(file_get_contents("https://freegeoip.net/json/{$ip}/github.com"));
     echo $details->city;
?>

只要使用
“https://freegeoip.net/json/{$ip}“
作为URL。github.com可能取自示例,您也可以使用主机名而不是IP地址进行查询