程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php查詢IP地址歸屬等信息

php查詢IP地址歸屬等信息

編輯:關於PHP編程

淘寶公司提供了一個很好用的IP地理信息查詢接口。
在這裡:http://ip.taobao.com/
TaobaoIPQuery2這個類將極大的簡化相關的信息查詢。

 

類 TaobaoIPQuery2 文件:

 <?   
   
         = 'http://ip.taobao.com/service/getIpInfo.php'        getIPInfo(          = (         ( === 0               ('IP address error', 5          =(          = self::queryIPInfo(          self::parseJSON(      
        queryIPInfo(          = (('ip'=>          =          =              CURLOPT_URL => ('%s?%s', self::, ),
             CURLOPT_RETURNTRANSFER => ,
             CURLOPT_AUTOREFERER => ,
             CURLOPT_FOLLOWLOCATION => ,
             CURLOPT_HEADER => ,
             CURLOPT_TIMEOUT => 3.0,
          curl_setopt_array(,           = curl_exec(         curl_close(                
        parseJSON(          = json_decode (,          ( === (                         ((, '5.3.0', '>='              =             ((self::[                   (self::[], 5             ('JSON parse error', 5      
        =          JSON_ERROR_NONE=>'No error has occurred',   
         JSON_ERROR_DEPTH=>'The maximum stack depth has been exceeded',   
         JSON_ERROR_CTRL_CHAR=>'Control character error, possibly incorrectly encoded',   
         JSON_ERROR_STATE_MISMATCH=>'Invalid or malformed JSON',   
         JSON_ERROR_SYNTAX=>'Syntax error',   
         JSON_ERROR_UTF8=>'Malformed UTF-8 characters, possibly incorrectly encoded',
  }

 

TaobaoIPQuery2.Class.php:

 <?         = 'http://ip.taobao.com/service/getIpInfo.php'        getIPInfo(          = (         ( === 0               ('IP address error', 5          =(          = self::queryIPInfo(          self::parseJSON(      
        queryIPInfo(          = (('ip'=>          =          =              CURLOPT_URL => ('%s?%s', self::, ),
             CURLOPT_RETURNTRANSFER => ,
             CURLOPT_AUTOREFERER => ,
             CURLOPT_FOLLOWLOCATION => ,
             CURLOPT_HEADER => ,
             CURLOPT_TIMEOUT => 3.0,
          curl_setopt_array(,           = curl_exec(         curl_close(                
        parseJSON(          = json_decode (,          ( === (                         ((, '5.3.0', '>='              =             ((self::[                   (self::[], 5             ('JSON parse error', 5      
        =          JSON_ERROR_NONE=>'No error has occurred',   
         JSON_ERROR_DEPTH=>'The maximum stack depth has been exceeded',   
         JSON_ERROR_CTRL_CHAR=>'Control character error, possibly incorrectly encoded',   
         JSON_ERROR_STATE_MISMATCH=>'Invalid or malformed JSON',   
         JSON_ERROR_SYNTAX=>'Syntax error',   
         JSON_ERROR_UTF8=>'Malformed UTF-8 characters, possibly incorrectly encoded',
  }

 

調用:

 = ["REMOTE_ADDR" =  taobaoIPQuery( = -> = -> = ->get_city();

 

 

另外新浪也提供接口:http://ipapi.sinaapp.com/

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved