php查询IP地址归属等信息_PHP教程
程序员文章站
2022-05-20 09:00:13
...
淘宝公司提供了一个很好用的IP地理信息查询接口。
在这里:http://ip.taobao.com/
TaobaoIPQuery2这个类将极大的简化相关的信息查询。
在这里: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/
推荐阅读
-
PHP curl伪造IP地址和header信息代码实例
-
php获取指定(访客)IP所有信息(地址、邮政编码、国家、经纬度等)的方法
-
php获取客户端IP地址、所在地、操作系统、浏览器信息
-
php通过淘宝API查询IP地址归属等信息
-
PHP获取当前服务器版本,Ip等详细信息
-
php二分法在IP地址查询中的应用
-
php限制ip地址范围的方法_PHP教程
-
php中使用getimagesize获取图片、flash等文件的尺寸信息实例_PHP教程
-
【php】利用新浪api接口与php获取远程数据的步骤,获取IP地址,并获取相应的IP归属地
-
【php】利用新浪api接口与php获取远程数据的方法,获取IP地址,并获取相应的IP归属地