webmaster at isag dot melbourne ¶5 年前
使用 GeoIP2,最简单的方法是
* 获取最新的 GeoIP2 Lite 数据库:https://dev.maxmind.com/geoip/geoip2/geolite2/
* 获取最新的 geoip2.phar:https://github.com/maxmind/GeoIP2-php/releases
<?php
require_once("geoip2.phar");
use GeoIp2\Database\Reader;
$reader = new Reader('/path/to/GeoLite2-City.mmdb');
$record = $reader->city($_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");
$>