1 Star 0 Fork 1

爱玲 / IpApi_by_ip2Region

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Ip2RegionApi.php 1.04 KB
Copy Edit Web IDE Raw Blame History
一朵灼灼华 authored 2019-01-03 13:57 . init
<?php
/**
* Ip2Region php client API
* @author Heanny<lzh@heanny.cn>
*/
header("Content-Type: text/html; charset=utf8");
function GetIpRegion($ip,$algorithm='B-tree',$method = 'btreeSearch'){
$dbFile = './data/ip2region.db';
switch ($algorithm) {
case 'binary':
$algorithm = 'Binary';
$method = 'binarySearch';
break;
case 'memory':
$algorithm = 'Memory';
$method = 'memorySearch';
break;
}
require dirname(__FILE__) . '/php/Ip2Region.class.php';
$ip2regionObj = new Ip2Region($dbFile);
if (strlen($ip) < 2 || $ip == 'quit') {
return null;
};
$s_time = getTime();
$data = $ip2regionObj->{$method}($ip);
$c_time = getTime() - $s_time;
$data['time']=$c_time;
$data['ip']=$ip;
// printf("%s|%s in %.5f ms\n", $data['city_id'], $data['region'], $c_time);
// print_r($data);
return $data;
}
function getTime()
{
return (microtime(true) * 1000);
}
$ip=$_REQUEST['ip'];
print_r( GetIpRegion($ip));
?>

Comment ( 0 )

Sign in for post a comment

Python
1
https://gitee.com/xiaoshen2017/IpApi_by_ip2Region.git
git@gitee.com:xiaoshen2017/IpApi_by_ip2Region.git
xiaoshen2017
IpApi_by_ip2Region
IpApi_by_ip2Region
master

Search