在GeoIP2中找不到读取器类


reader class not found in GeoIP2

我正在尝试安装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');
?>

有人能帮忙吗?

这对我很有用,谢谢@Greg Oschwald!由于我没有使用composer,我现在的代码是:

<?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;
}

从https://github.com/maxmind/GeoIP2-php/releases

尝试更改:

使用GeoIp2''Database''reader;

至:

使用GeoIp2''Database''Reader;

尝试将php版本升级到7.1.33或更高版本

确保安装GeoIP2软件包:

composer require geoip2/geoip2