【问题标题】:IP with JSON file带有 JSON 文件的 IP
【发布时间】:2017-04-30 05:09:28
【问题描述】:

伙计们。我写了一小段代码来获取站点访问者的IP,所以想问一下,我应该把$ip放在哪里才能得到当前位置。

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

【问题讨论】:

    标签: php location ip php-7


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-01
      • 2013-07-03
      • 1970-01-01
      • 2021-07-20
      • 2023-03-30
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多