alestro / ipgeobase
此包已被废弃,不再维护。没有建议的替代包。
IpGeoBase in sql
v1.0
2017-11-04 13:21 UTC
Requires
- php: >= 7.0.0
This package is auto-updated.
Last update: 2023-03-11 16:09:37 UTC
README
$ composer require shelamkoff/ipgeobase
使用
use alestro\ipgeobase\IpGeoBase;
$geobase = new IpGeoBase($pdo) 或 $geobase = new IpGeoBase($dsn, $user, $password);
$geobase->create() // 在数据库中创建 geobase 和 geobase_cities 表并填充它们。
$geobase->update() // 更新数据库。
$data = $geobase->find('217.107.124.206'); // 如果 ip 无效,将抛出 Uncaught Exception: Invalid ip-adress. 如果 ip 在数据库中不存在,将抛出 Uncaught Exception: Ip-aress not found in the database.
var_dump($data);
针对俄罗斯和乌克兰的 ip
array(11) { ["long_ip1"]=> string(10) "3647684608" ["long_ip2"]=> string(10) "3647717375" ["ip1"]=> string(12) "217.107.64.0" ["ip2"]=> string(15) "217.107.191.255" ["country"]=> string(2) "RU" ["city_id"]=> string(4) "2097" ["city"]=> string(12) "Москва" ["region"]=> string(12) "Москва" ["district"]=> string(56) "Центральный федеральный округ" ["latitude"]=> string(7) "55.7558" ["longitude"]=> string(7) "37.6176" }
针对所有其他 ip
array(6) { ["long_ip1"]=> string(8) "84557824" ["long_ip2"]=> string(8) "84557824" ["ip1"]=> string(9) "5.10.64.0" ["ip2"]=> string(9) "5.10.64.0" ["country"]=> string(2) "NL" ["city_id"]=> NULL }