Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2018 10:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
require_once '/usr/share/php/GeoIP2-php/vendor/autoload.php';
use GeoIp2\Database\Reader;
// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader('/usr/share/GeoIP/GeoLite2-Country.mmdb');
// Replace "city" with the appropriate method for your database, e.g.,
// "country".
$record = $reader->country('');
print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['ja'] . "\n"); // 'アメリカ合衆国'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment