bobey/geoip2-geolite2-composer

此包的最新版本(v1.6.0)没有可用的许可信息。

这个微型存储库旨在通过composer在您的项目中轻松地要求GeoIP2 / GeoLite2数据库。

v1.6.0 2018-12-19 09:23 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:13:39 UTC


README

描述

这个微型存储库旨在通过composer在您的项目中轻松地要求GeoIP2 / GeoLite2数据库。如果您与GeoIP2 PHP API结合使用,这将特别有用。

通过composer安装

只需在项目根目录中运行以下命令

composer require bobey/geoip2-geolite2-composer

与GeoIP2 PHP API一起使用

composer require geoip2/geoip2:~2.0

城市示例重写

以下示例是GeoIP2 PHP API README中提供的示例,已重写以在您的 vendors 目录中查找GeoLite2数据库。

<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;

// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader('vendor/bobey/geoip2-geolite2-composer/GeoIP2/GeoLite2-City.mmdb');

// 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

更新

GeoLite2数据库在每月的第一个星期二更新。我将尽可能频繁地更新和标记此存储库的新版本。在此期间,如果您想自己更新数据库,只需fork存储库,运行以下更新脚本命令

./scripts/update.sh

然后,只需发起一个pull request!

许可

GeoLite2数据库在Creative Commons Attribution-ShareAlike 3.0 Unported License下分发。满足归属要求的方法是在所有提及此数据库功能或使用的广告和文档中包括以下内容

本产品包含由MaxMind创建的GeoLite2数据,可在http://www.maxmind.com获取。