Geo IP ロケーション

はじめに

GeoIP 拡張モジュールを使用すると、IP アドレスの場所を探すことができます。 市、州、国、経度、緯度そして ISP や接続方式などの情報が GeoIP を用いて取得できます。

警告

この拡張モジュールは、MaxMind の現在の "GeoIP2" データベースをサポートしません。 "GeoIP legacy" データベース・ファイルのみサポートします。

add a note

User Contributed Notes 2 notes

up
31
mark at moderndeveloperllc dot com
12 years ago
It should be noted that this extension has now been superseded by the GeoIP2 API that MaxMind now produces. There is a pure-PHP set of classes and a C library and extension you can optionally install. The code can be found in various projects on MaxMind's GitHub page: https://github.com/maxmind/
up
28
webmaster at isag dot melbourne
7 years ago
With GeoIP2, the easiest way is to:

* Grab the latest GeoIP2 Lite Database(s): https://dev.maxmind.com/geoip/geoip2/geolite2/
* Grab the latest geoip2.phar: https://github.com/maxmind/GeoIP2-php/releases

<?php
require_once("geoip2.phar");
use GeoIp2\Database\Reader;
// City DB
$reader = new Reader('/path/to/GeoLite2-City.mmdb');
$record = $reader->city($_SERVER['REMOTE_ADDR']);
// or for Country DB
// $reader = new Reader('/path/to/GeoLite2-Country.mmdb');
// $record = $reader->country($_SERVER['REMOTE_ADDR']);
print($record->country->isoCode . "\n");
print($record->country->name . "\n");
print($record->country->names['zh-CN'] . "\n");
print($record->mostSpecificSubdivision->name . "\n");
print($record->mostSpecificSubdivision->isoCode . "\n");
print($record->city->name . "\n");
print($record->postal->code . "\n");
print($record->location->latitude . "\n");
print($record->location->longitude . "\n");
$>
To Top