14行PHP代码获取客户端IP地址经纬度及所在城市
时间:2021-07-01 10:21:17
帮助过:26人阅读
-
- $getIp=$_SERVER["REMOTE_ADDR"];
- echo 'IP:',$getIp;
- echo '
'; - $content = file_get_contents("http://api.map.baidu.com/location/ip?ak=7IZ6fgGEGohCrRKUE9Rj4TSQ&ip={$getIp}&coor=bd09ll");
- $json = json_decode($content);
-
- echo 'log:',$json->{'content'}->{'point'}->{'x'};//按层级关系提取经度数据
- echo '
'; - echo 'lat:',$json->{'content'}->{'point'}->{'y'};//按层级关系提取纬度数据
- echo '
'; - print $json->{'content'}->{'address'};//按层级关系提取address数据
- ?>
-
|
PHP