我下载并解压了 GeoLite2-City.mmdb、GeoLite2-Country.mmdb。两者都在htdocs\geoip\
然后,我运行了这个脚本。麻烦的是,这东西是怎么工作的?require_once 'vendor/autoload.php';
应该包含什么?我在这里有什么遗漏吗。我曾经使用以 .dat 文件形式提供的旧版本,并且对它们没有任何问题。这些 .mmdb 对我来说有点难以破解。当用户在页面上使用搜索工具时,我要做的就是获取国家代码、国家名称和其他数据以存储在数据库中。我该怎么办?
我的测试页取自网站
<?php
require_once 'vendor/autoload.php'; //What is this supposed to contain?
use GeoIp2\Database\Reader; // What is this too?
// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader($_SERVER['DOCUMENT_ROOT'].'\geoip\GeoIP2-City.mmdb'); // Where my DB resides
// 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['zh-CN'] . "\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
?>