14 lines of PHP code to obtain the client's IP address, longitude, latitude and city

WBOY
Release: 2016-07-25 08:44:08
Original
1268 people have browsed it
  1. $getIp=$_SERVER["REMOTE_ADDR"];
  2. echo 'IP:',$getIp;
  3. echo '
    ';
  4. $content = file_get_contents("http ://api.map.baidu.com/location/ip?ak=7IZ6fgGEGohCrRKUE9Rj4TSQ&ip={$getIp}&coor=bd09ll");
  5. $json = json_decode($content);
  6. echo 'log:',$json- >{'content'}->{'point'}->{'x'};//Extract longitude data according to hierarchical relationship
  7. echo '
    ';
  8. echo 'lat:', $json->{'content'}->{'point'}->{'y'};//Extract latitude data according to hierarchical relationship
  9. echo '
    ';
  10. print $json ->{'content'}->{'address'};//Extract address data by hierarchical relationship
  11. ?>
Copy code

PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template