maurokouti / php-geoip-shim
PHP GeoIP shim to support legacy geoip_* functions with the GeoIP2 .mmdb database files.
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-04-26 17:52:17 UTC
README
As MaxMind retires GeoIP Legacy databases
in May 2022 and the fact that geoip
PHP extension is not supported in PHP 8.0
this library might be useful as a quickfix for the projects with legacy codebase.
Install via Composer
composer require maurokouti/php-geoip-shim
Usage
<?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);
Supported functions
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