maurokouti / php-geoip-shim
PHP GeoIP shim 用于支持使用 GeoIP2 .mmdb 数据库文件的旧版 geoip_* 函数。
dev-master
2021-08-26 11:36 UTC
Requires
- php: >=7.3
- geoip2/geoip2: ^2.11
Requires (Dev)
- ext-json: *
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^0.12.96
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-26 18:42:48 UTC
README
由于 MaxMind 在 2022 年 5 月 退役了 GeoIP Legacy 数据库,并且 PHP 8.0 中不再支持 geoip PHP 扩展,这个库可能对需要快速修复旧代码库的项目很有用。
通过 Composer 安装
composer require maurokouti/php-geoip-shim
使用方法
<?php \GeoIPShim\GeoIp2::init([ '/var/lib/GeoIP/GeoIP2-Country.mmdb', '/var/lib/GeoIP/GeoIP2-ISP.mmdb', ]); // by IP address $ipAddress = '1.2.3.4'; $countryCode = geoip_country_code_by_name($ipAddress); $ispName = geoip_isp_by_name($ipAddress); // by hostname $hostname = 'github.com'; $countryCode = geoip_country_code_by_name($hostname); $ispName = geoip_isp_by_name($hostname);
支持的功能
geoip_asnum_by_name(string $hostname): string
geoip_continent_code_by_name(string $hostname): string
geoip_country_code_by_name(string $hostname): string
geoip_country_name_by_name(string $hostname): string
geoip_database_info(int $database = GEOIP_COUNTRY_EDITION): string
geoip_db_avail(int $database): bool
geoip_db_filename(int $database): string
geoip_db_get_all_info(): array
geoip_domain_by_name(string $hostname): string
geoip_isp_by_name(string $hostname): string
geoip_netspeedcell_by_name(string $hostname): string
geoip_org_by_name(string $hostname): string
geoip_record_by_name(string $hostname): array
geoip_region_by_name(string $hostname): array