maurokouti / php-geoip-shim
PHP GeoIP shim to support legacy geoip_* functions with the GeoIP2 .mmdb database files.
Installs: 323
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/maurokouti/php-geoip-shim
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: 2026-01-26 21:32:40 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): stringgeoip_continent_code_by_name(string $hostname): stringgeoip_country_code_by_name(string $hostname): stringgeoip_country_name_by_name(string $hostname): stringgeoip_database_info(int $database = GEOIP_COUNTRY_EDITION): stringgeoip_db_avail(int $database): boolgeoip_db_filename(int $database): stringgeoip_db_get_all_info(): arraygeoip_domain_by_name(string $hostname): stringgeoip_isp_by_name(string $hostname): stringgeoip_netspeedcell_by_name(string $hostname): stringgeoip_org_by_name(string $hostname): stringgeoip_record_by_name(string $hostname): arraygeoip_region_by_name(string $hostname): array