smalldogs/ip2country
最新稳定版本:1.1.0
Composer 安装命令:
composer require smalldogs/ip2country
包简介
Laravel package to lookup the country associated with an IPv4 address
README 文档
README
Laravel package to lookup the country associated with an IPv4 address. Developed with an eye to keeping it as lightweight and lookups as fast as possible. Creates and populates a local database table, so there are no external requests being made during runtime.
This package includes GeoLite data created by MaxMind, available from http://www.maxmind.com. The updated free downloadable database is released the first Tuesday of each month. I'll attempt to ensure to update this package each time.
Current IP Mapping Table
Doesn't seem to change much from month to month. Current version was released by MaxMind February 4, 2015
How to Update Mapping DB Table
If you have already installed and setup the ip2country package, but want to update the IP database mappings. First, get the latest ip2country package.
composer update
or, to only update this pacakage
composer update smalldogs/ip2country
Then, update your database by running the new migration.
php artisan migrate --package="smalldogs/ip2country"
How to Install
1. Require the package with composer.
composer require "smalldogs/ip2country"
2. Create and populate the database lookup table.
php artisan migrate --package="smalldogs/ip2country"
3. Add the service to your providers array in app/config/app.php
'providers' => array( 'Smalldogs\Ip2Country\Ip2CountryServiceProvider', //[...] );
How to Use
// Returns the 2 letter country code for the user, eg: 'US' $myCountryCode = Ip2Country::get(); // Returns the full name of the country, eg: 'United States' $myCountryName = Ip2Country::getFull(); // Get the country for someone other than user on the page $someonesIpAddress = '192.168.0.1'; $someonesCountryCode = Ip2Country::get($someonesIpAddress);
Configuration
By default, if the IP address is not found in the lookup table, it will return 'US' as a country code, and 'United States' as a country name. You can customize this in the config.
php artisan config:publish smalldogs/ip2country
Then navigate to app/config/packages/smalldogs/ip2country/config.php.
return array( // If IP address is not found, what country is returned 'default_country_code' => 'US', 'default_country_name' => 'United States', // Since our data will change, at most, once a month. Cache the Ip lookup for a day // Default: 1 day. Set to 0 or null to disable. 'cache_results' => 60 * 24 );
If you don't want anything returned if the IP address is not found, simply set each of these to => null
smalldogs/ip2country 适用场景与选型建议
smalldogs/ip2country 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.01k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2014 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「location」 「IP」 「ipv4」 「geocode」 「country」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 smalldogs/ip2country 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 smalldogs/ip2country 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 smalldogs/ip2country 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDRAM.
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
PHP Library for manipulating network addresses (IPv4 and IPv6)
Manages IPv4 and IPv6 addresses and subnets
A Symfony2 Bundle to handle geographic location of your entities
Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.
统计信息
- 总下载量: 1.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2014-11-21