looking4soul / ipgeo
查找IP的地理位置
1.0.1
2016-11-25 13:45 UTC
Requires
- php: >=5.4.0
- league/csv: ^8.1.2
- predis/predis: ^1.1.1
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2024-09-23 14:29:08 UTC
README
#IpGeo
查找IP的地理位置。
##用法
###安装
composer install
###设置Redis
在127.0.0.1:6379上启动redis
###下载GeoLite2
http://dev.maxmind.com/geoip/geoip2/geolite2/
###将Ip Geo导入Redis
<?php require 'vendor/autoload.php'; $block = 'path/to/GeoLite2-City-Blocks-IPv4.csv'; $location = 'path/to/GeoLite2-City-Locations-zh-CN.csv'; $ipgeo = new \Looking4soul\IpGeo\IpGeo(); $ipgeo->import($block, $location);
###通过IP搜索城市
<?php require 'vendor/autoload.php'; $ipgeo = new \Looking4soul\IpGeo\IpGeo(); var_dump($ipgeo->find_city_by_ip('140.237.24.176')); /*expected output is array of city and country in zh-CN. array(2) { [0]=> string(0) "" [1]=> string(6) "中国" } */
##许可证
MIT许可证(MIT)。