這篇文章主要介紹“淘寶ip地址查詢類方法教程”,在日常操作中,相信很多人在淘寶ip地址查詢類方法教程問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”淘寶ip地址查詢類方法教程”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
復制代碼 代碼如下:
<?php
class taobaoIPQuery {
private $m_ip;
private $m_content;
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, "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 error!");
}
} else {
exit("ip address must be not empty!");
}
}
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->m_content->{'data'}->{'country'};
}
public function get_city() {
return $this->m_content->{'data'}->{'city'};
}
}
調用很簡單
復制代碼 代碼如下:
$ip = $_SERVER["REMOTE_ADDR"];
$ipquery = new taobaoIPQuery($ip);
$region = $ipquery->get_region();
$country = $ipquery->get_country();
$city = $ipquery->get_city();
到此,關于“淘寶ip地址查詢類方法教程”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注創新互聯網站,小編會繼續努力為大家帶來更多實用的文章!
當前文章:淘寶ip地址查詢類方法教程-創新互聯
網站鏈接:http://vcdvsql.cn/article28/ddgicp.html
成都網站建設公司_創新互聯,為您提供網站營銷、靜態網站、企業網站制作、App設計、外貿網站建設、自適應網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯