Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created December 8, 2018 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandanote-info/889b66591b9e0ee276cfdfdf57112fc2 to your computer and use it in GitHub Desktop.
Save pandanote-info/889b66591b9e0ee276cfdfdf57112fc2 to your computer and use it in GitHub Desktop.
GeoLite2の動作確認用のPHPのコード。
<?php
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-City.mmdb');
// Replace "city" with the appropriate method for your database, e.g.,
// "country".
$record = $reader->city('128.101.101.101');
print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['ja'] . "\n"); // 'アメリカ合衆国'
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
print($record->city->name . "\n"); // 'Minneapolis'
print($record->postal->code . "\n"); // '55455'
print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment