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

Source: Internet
Author: User
14 lines of PHP code to obtain the client IP address longitude and latitude and city

  1. $ GetIp = $ _ SERVER ["REMOTE_ADDR"];
  2. Echo 'IP: ', $ getIp;
  3. Echo'
    ';
  4. $ Content = file_get_contents ("http://api.map.baidu.com/location/ip? Ak = 7iz6fggegohcrrkue94254tsq & ip ={$ getIp} & coor = bd09ll ");
  5. $ Json = json_decode ($ content );
  6. Echo 'log: ', $ json-> {'content'}-> {'point'}-> {'X'}; // extracts longitude data based on hierarchical relationships.
  7. Echo'
    ';
  8. Echo 'lat: ', $ json-> {'content'}-> {'point'}-> {'y'}; // extracts latitude data based on hierarchical relationships.
  9. Echo'
    ';
  10. Print $ json-> {'content'}-> {'address'}; // extracts address data based on hierarchical relationships
  11. ?>


PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.