atchondjo/geoip2country
Composer 安装命令:
composer require atchondjo/geoip2country
包简介
A lightweight but powerful IP address lookup database solution to determine visitors country
README 文档
README
An IP address is only the beginning of endless possibilities, adventures and developments...
What's GeoIP2Country PRO?
A PHP IP Address Geolocation library to help you identify visitors geographical location. This component is Build with an eye to keeping it as lightweight and lookups as fast as possible. And there are no external requests being made during runtime. So, if you need to get your website visitor's country and you don't want to use any API then this is the best solution for you. The project include methods to quickly update your GEOIP DATABASE with the least possible human intervention (for donors only).
What's new in this release?
- Complete refactoring and optimization of processing algorithms
- A new database engine (combining security and efficiency)
- A new component dedicated to updating the database?
- A repository based on statistical data from ICANN (Internet Corporation for Assigned Names and Numbers)
NOTE:
In order to encourage people to support this project, database update components are not included in this repository as they are for donors only. Thus any donor will receive a full copy of this software, including the component that will help him to make his GEOIP database stay up to date. However, other users can still use the software as published here. Only the database update functionality will not be available
Requirements
- pdo_sqlite (runtime deps)
- php_curl (for update only)
Installation And Initialisation :
These instructions will get you a copy of the project up and running on your local machine. there are two options:
- import(copy) GeoIP2Country files into a specific folder of your project
- Using Composer installer(Recommended) by typing the following command:
composer require atchondjo/geoip2country
Usage: (using Composer autoloader)
require __DIR__ . '/vendor/autoload.php'; try { $IP2Country = new iriven\GeoIP2Country(); } catch (\Throwable $th) { trigger_error($th->getMessage(), E_USER_ERROR); }
Getting Country code from given IP address:
$ipAddress_1='2a00:1450:4007:816::2004'; $ipAddress_2='37.140.250.97'; $ipAddress_3='2001:41d0:301::21'; $ipAddress_4='216.58.201.228'; $ipAddress_5='188.165.53.185'; $ipAddress_6='10.10.201.12'; echo '<pre>'; echo $IP2Country->resolve($ipAddress_1).PHP_EOL; echo $IP2Country->resolve($ipAddress_2).PHP_EOL; echo $IP2Country->resolve($ipAddress_3).PHP_EOL; echo $IP2Country->resolve($ipAddress_4).PHP_EOL; echo $IP2Country->resolve($ipAddress_5).PHP_EOL; echo $IP2Country->resolve($ipAddress_6).PHP_EOL;
Getting current visitor Country code (auto detect his IP address):
echo '<pre>'; echo $IP2Country->resolve().PHP_EOL; /** resolve() method called without any argument */
Retrieving Country name:
Because one of my publications already deals with the recovery of a country's name from its ISO code. I chose in this project to limit myself to the only search of the country's ALPHA2 ISO code from a given ip address. So, to retrieve the country name (and much more), you must instantiate the "WorldCountriesDatas" class available from HERE, and pass the result of the previous command as follows:
$CountryName ='n/a'; $CountryCode = $IP2Country->resolve($ipAddress); if(!$IP2Country->isReservedAddress($ipAddress)) { require_once 'WorldCountriesDatas.php'; $DataProvider = new \Iriven\WorldCountriesDatas(); $CountryName = $DataProvider->getCountryName($CountryCode); }
Updating GeoIP datas: (for Donors only)
require __DIR__ . '/vendor/autoload.php'; try { $IP2CountryBackend = new iriven\GeoIP2CountryServer(); $IP2CountryBackend->updateDatabase(); } catch (\Throwable $th) { trigger_error($th->getMessage(), E_USER_ERROR); } /* * NOTE: In order to encourage people to support this project, database update components are not included in this * repository as they are for donors only. Thus any donor will receive a full copy of this software, * including the component that will help him to make his GEOIP database stay up to date. */
Compatibility:
- IPV4
- IPV6
Authors
- Alfred TCHONDJO - Project Initiator - Iriven France
License
This project is licensed under the GNU General Public License V3 - see the LICENSE file for details
Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
Acknowledgments
- This project uses GeoIp data by ICANN, available from Here
Disclaimer
If you use this library in your project please add a backlink to this page by this code.
<a href="https://github.com/iriven/GeoIP2Country" target="_blank">This Project Uses Alfred's TCHONDJO GeoIP2Country PRO.</a>
atchondjo/geoip2country 适用场景与选型建议
atchondjo/geoip2country 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.57k 次下载、GitHub Stars 达 34, 最近一次更新时间为 2022 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「geolocation」 「geoip」 「ipaddress」 「ip2location」 「IP2Country」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atchondjo/geoip2country 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atchondjo/geoip2country 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atchondjo/geoip2country 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
Maps in minutes. Powered by the Google Maps API.
The official PHP library for apiip.net that allowing customers to automate IP address validation and geolocation lookup in websites, applications and back-office system. Visit our API docs at https://apiip.net/documentation
Supports GeoIP services (sypexgeo.net).
PHP GeoIP client
Alfabank REST API integration
统计信息
- 总下载量: 4.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-12-10