Taobao provides a very useful IP geographic information query interface. Here: http://ip.taobao.com/
The following taobaoIPQuery class will greatly simplify related information query.
Copy code The code is as follows:
class taobaoIPQuery {
private $m_ip;
private $m_content;
public function __construct($ip) {
if (isset($ip)) {
$this->m_ip = $ip : () ;
curl_setopt($url_handle, CURLOPT_URL, "http://ip.taobao.com/service/getIpInfo.php?ip=" . $this->m_ip);
curl_setopt($url_handle, CURLOPT_RETURNTRANSFER, true);
$this->m_content = curl_exec($url_handle);
curl_close($url_handle);
if ($this->m_content) {
$ this->m_content = json_decode($this->m_content);
if ($this->m_content->{'code'} == 1) {
exit("query error!");
} } Else {
EXIT ("Curl E error!"); 🎜> }
public function get_region() {
return $this->m_content->{'data'}->{'region'};
}
public function get_isp() {
return $this->m_content->{'data'}->{'isp'};
}
public function get_country() { Return $ this-& gt; m_content- & gt; {'data'}-& gt; {'country'};
Public function get_city () {
Return $ this ->m_content->{'data'}->{'city'};
}
}
The call is very simple
Copy code
The code is as follows:
$ip = $_SERVER["REMOTE_ADDR"];$ipquery = new taobaoIPQuery($ip);
$region = $ipquery->get_region();
$country = $ipquery->get_country();
$city = $ipquery->get_city() ;
http://www.bkjia.com/PHPjc/676912.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/676912.html
TechArticle
Taobao provides a very useful IP geographical information query interface. Here: http://ip.taobao.com/ The following taobaoIPQuery class will greatly simplify related information query. Copy code...
Statement: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