我试图提取有关访问者 IP 地址的正确信息:
ISP
Organization
City
Region
Country
我可以通过 json_decode 和 file_get_contents 提取这些信息:
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}")); // or from whatismyipaddress.com
echo $details->city;
我也可以自己写代码(geoip)
但这不是提取此信息的正确方法(通过使用 curl),
并且唯一返回正确信息的网站是http://whatismyipaddress.com/
我尝试使用 geoip 但我的 php 返回不正确的信息。