Taobao IP address query class share

Source: Internet
Author: User

  needs to display the reviewer's geographical attributes, which can be achieved by recording the geographical information of the member's IP, the following provides an IP address Taobao query class, simplifying the relevant information inquiries, we refer to the use of bar  

Taobao Company provides a very useful IP geographic information query interface. Here:  Below this taobaoipquery class will greatly simplify the relevant information query.   Code as follows: <?php   class Taobaoipquery {      private $m _ip;     private $m _content; nbsp     Public Function __construct ($IP) {        if (Isset ($IP)) {            $this->m_ip = $ip;        } else {            $this->m_ip = "";        }         if (!empty ($this->m_ip)) {            $url _handle = Curl_init ();             curl_setopt ($url _handle, Curlopt_url, " Getipinfo.php?ip= ". $this->m_ip);             curl_setopt ($url _handle, Curlopt_returntransfer, true);             $this->m_content = curl_exec ($url _handle);         &NBSp   Curl_close ($url _handle);             if ($this->m_content) {              &NBS P $this->m_content = Json_decode ($this->m_content);                 if ($this->m_content->{' code '} = = 1) {                    exit ("Query error!");                            } else {                exit ("Curl error!");                    } else {            Exit ("IP address must is not empty!");        }     {      public Function get_region () {      &NB Sp return $this->m_content->{' data '}->{' region '};    }       public Function Get_isp() {        return $this->m_content->{' data '}->{' ISP '};    }       Public Function Get_country () {        return $this->m_content->{' data '}->{' country '}; &nb Sp  }       public Function get_city () {        $this->m_content->{' da Ta '}->{' city '};    }  }     Call very simple code as follows: $ip = $_server["REMOTE_ADDR"]; $ipquery = new Taobaoipquery ($IP); $region = $ipquery->get_region (); $country = $ipquery->get_country (); $city = $ipquery->get_city ();  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.