我们如何在php中使用这个json呢?
$ curl ipinfo.io
{
"ip": "178.78.135.10",
"hostname": "No Hostname",
"city": null,
"region": null,
"country": "AM",
"loc": "40.0000,45.0000",
"org": "AS49363 Orange Armenia CJSC"
}我在这里找到了这个:http://ipinfo.io/
发布于 2014-08-30 21:39:16
使用file_get_contents获取数据,使用json_decode将其转换为php。
$data = json_decode(file_get_contents("http://ipinfo.io/"));
print_r($data); /* print results */发布于 2014-08-30 21:56:00
使用此服务器端(例如PHP)将显示您的服务器的 IP和信息,而不是用户的。
如果您需要有关用户的信息,则需要使用JavaScript来实现their JSONP API,让用户的浏览器调用该接口并返回有关用户IP的信息。
或者,您需要为用户IP调用他们的API:
$data = json_decode(file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/json"));https://stackoverflow.com/questions/25582908
复制相似问题