g4 / geoip
geoip php 库
2.0.0
2023-11-13 07:58 UTC
Requires
- php: >=8.2
- ext-mbstring: *
- geoip2/geoip2: >=2.13.0
Requires (Dev)
- phpunit/phpunit: 10.*
This package is auto-updated.
Last update: 2024-09-13 09:36:55 UTC
README
geoip - php 库
安装
通过 Composer
composer require g4/geoip
需求
- PHP GeoIP 扩展 https://php.ac.cn/manual/en/geoip.setup.php
- Maxmind GeoIP 数据库 http://dev.maxmind.com/
- Maxmind GeoIP2-City 数据库
安装所需的软件包(CentOS, Redhat)
- yum install GeoIP
- yum install GeoIP-devel
- yum install geoipupdate
- pecl install geoip
用法
<?php $geoIp = new \G4\GeoIP\GeoIP('127.0.0.1'); // "area_code" -- The PSTN area code (ex: 212) echo $geoIp->getAreaCode(); // "dma_code" -- Designated Market Area code (USA and Canada only) echo $geoIp->getDmaCode(); // "city" -- The city echo $geoIp->getCity(); // "continent_code" -- Two letter continent code echo $geoIp->getContinentCode(); // "country_code" -- Two letter country code echo $geoIp->getCountryCode(); // "country_code3" -- Three letter country code echo $geoIp->getCountryCode3(); // "country_name" -- The country name echo $geoIp->getCountryName(); // IP address echo $geoIp->getIp(); // "latitude" -- The Latitude as signed double echo $geoIp->getLatitude(); // "longitude" -- The Longitude as signed double echo $geoIp->getLongitude(); // "postal_code" -- The Postal Code, FSA or Zip Code echo $geoIp->getPostalCode(); // "region" -- The region code (ex: CA for California) echo $geoIp->getRegion();
开发
安装依赖项
$ make install
运行测试
$ make test
许可证
(MIT 许可证) 详细信息见 LICENSE 文件...