我正在尝试安装Maxmind的GeoIP2。我按照他们的指示做了所有事情,我仍然遇到了这个恼人的错误:
Fatal error: Class 'GeoIp2\Database\reader' not found in C:\Program Files\*\*\localweb\GeoIp2\index.php on line 19
这是脚本在index.php中的样子:
<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\reader;
// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader('C:/Program Files/*/*/localweb/GeoIp2/Database/GeoLite2-Country.mmdb');
$record = $reader->country('128.101.101.101');
?>
有人可以帮忙吗?
答案 0 :(得分:1)
尝试更改:
使用GeoIp2 \ Database \ reader;
为:
使用GeoIp2 \ Database \ Reader;
答案 1 :(得分:0)
这对我有用,谢谢@Greg Oschwald! 由于我没有使用作曲家,我现在的代码是:
<?php
require 'geoip2.phar';
try {
$reader = new GeoIp2\Database\Reader('GeoLite2-City.mmdb');
$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
} catch (Exception $e) {
echo 'Could not open Phar: ', $e;
}
获取该phar文件
答案 2 :(得分:0)
尝试将php版本升级到7.1.33或更高版本