php利用百度地图ip-api获取ip归属地

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangshuainan/article/details/87087386

通过百度地图的WEB服务API中的普通ip定位API进行获取操作http://lbsyun.baidu.com/index.php?title=webapi/ip-api

创建应用—>设置名称、类别、白名单

ak参数是你创建成功之后复制过来的

function get_ip_city($ip)
{
$url="http://api.map.baidu.com/location/ip?ak=此参数请看说明&ip=".$ip;
$ipinfo=json_decode(file_get_contents($url));
$location = $ipinfo->{'content'}->{'address'};
return $location;
}

用于个人记录使用,大神勿喷

猜你喜欢

转载自blog.csdn.net/yangshuainan/article/details/87087386