淘宝公司提供了一个很好用的ip地理信息查询接口。
在这里:http://ip.taobao.com/
taobaoipquery2这个类将极大的简化相关的信息查询。 $ip)); $ch = curl_init(); $options = array( curlopt_url => sprintf('%s?%s', self::$_requesturl, $query), curlopt_returntransfer => true, curlopt_autoreferer => false, curlopt_followlocation => false, curlopt_header => false, curlopt_timeout => 3.0, ); curl_setopt_array($ch, $options); $content = curl_exec($ch); curl_close($ch); return $content; } private static function parsejson($json){ $o = json_decode ($json, true); if(false === is_null($o)){ return $o; } if (version_compare(php_version, '5.3.0', '>=')) { $errorcode = json_last_error(); if(isset(self::$_jsonparseerror[$errorcode])){ throw new exception(self::$_jsonparseerror[$errorcode], 5); } } throw new exception('json parse error', 5); } private static $_jsonparseerror = array( 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', );}
$ip)); $ch = curl_init(); $options = array( curlopt_url => sprintf('%s?%s', self::$_requesturl, $query), curlopt_returntransfer => true, curlopt_autoreferer => false, curlopt_followlocation => false, curlopt_header => false, curlopt_timeout => 3.0, ); curl_setopt_array($ch, $options); $content = curl_exec($ch); curl_close($ch); return $content; } private static function parsejson($json){ $o = json_decode ($json, true); if(false === is_null($o)){ return $o; } if (version_compare(php_version, '5.3.0', '>=')) { $errorcode = json_last_error(); if(isset(self::$_jsonparseerror[$errorcode])){ throw new exception(self::$_jsonparseerror[$errorcode], 5); } } throw new exception('json parse error', 5); } private static $_jsonparseerror = array( 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', );}
