sunsgne / ip-attribution
This package is abandoned and no longer maintained.
No replacement package was suggested.
Webman plugin workbunny/ip-attribution
0.1.0
2022-09-15 08:19 UTC
Requires
- php: >=7.4
- geoip2/geoip2: ~2.0
- workerman/webman-framework: 1.4.3
README
workbunny/ip-attribution
🐇 geoip2 is applied to PHP to obtain IP geographic location. 🐇
geoip2 is applied to PHP to obtain IP geographic location
简介
libs/mmdb
最后更新时间:2022-09-14ip-attribution
是基于geoip2
作为底层,依托mmdb
查询ip归属地及asn信息- 本项目来源于geoip2/geoip2,感谢MaxMind 工作组的开源
安装
composer require workbunny/ip-attribution
使用
范例
use workbunny\IpLocation\Location; try { $location = Location::$instance; var_dump($location->city("1.1.1.1")); }catch (\workbunny\IpLocation\exception\IpLocationException $exception){ }
获取IP所在城市
use workbunny\IpLocation\Location; try { $location = new Location(); var_dump($location->city("1.1.1.1")); }catch (\workbunny\IpLocation\exception\IpLocationException $exception){ }
获取IP地址ASN信息
use workbunny\IpLocation\Location; try { $location = new Location(); var_dump($location->asn("1.1.1.1")); }catch (\workbunny\IpLocation\exception\IpLocationException $exception){ }
获取IP所在国家
use workbunny\IpLocation\Location; try { $location = new Location(); var_dump($location->country("1.1.1.1")); }catch (\workbunny\IpLocation\exception\IpLocationException $exception){ }
webman 中使用
config配置文件
return [ 'enable' => true, //加载配置项 'config' => "default", 'default' => [ //语言 "language" => ['zh-CN'], //mdb数据路径,(默认不指定,加载包内库) "mdbFileDir" => "", //未获取时默认标识 "defaultIdentifier" => "NON" ], ];
应用
use workbunny\IpLocation\Location; try { $location = G(Location::class); var_dump($location->country("1.1.1.1")); var_dump($location->asn("1.1.1.1")); var_dump($location->city("1.1.1.1")); }catch (\workbunny\IpLocation\exception\IpLocationException $exception){ }
运行
./webman start OR php start.php start