PHP access to user real IP, Taobao IP interface to obtain IP location

Source: Internet
Author: User
Tags array get ip interface access

You do not need an IP library, update-free.
Taobao IP Library: http://ip.taobao.com
Thanks for the 5 floor reminder.

/**  * Get user real IP  */function GetIP () {    static $realip;     if (Isset ($_server)) {&NB Sp       if (Isset ($_server["Http_x_forwarded_for")) {            $realip = $_s erver["Http_x_forwarded_for"];        } else if (Isset ($_server["Http_client_ip")) {            $rea Lip = $_server["Http_client_ip"];        } else {            $realip = $_server["REMOTE_ADDR"];   & nbsp    }    } else {        if (getenv ("Http_x_forwarded_for")) {    &nbs P       $realip = getenv ("Http_x_forwarded_for");        } else if (getenv ("Http_client_ip")) {            $realip = Get Env ("Http_client_ip");        } else {            $realip = getenv ("Remote_ADDR ");        }     {        return $realip;    /**  * get IP   location  * Taobao IP interface  * @Return: array  */function getcity ($ip) {$url = " Http://ip.taobao.com/service/getIpInfo.php?ip= ". $ip; $ip =json_decode (file_get_contents ($url)); if ((string) $ip->code== ' 1 ') {  return false;  }   $data = (array) $ip->data; return $data; }

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.