buonzz / laravel-4-freegeoip
此包已被废弃,不再维护。未建议替代包。
Laravel 4 库,用于检测访客的地理位置信息
v1.0.3
2015-01-08 10:18 UTC
Requires
- php: >=5.3.7
- ext-curl: *
- lib-curl: *
Requires (Dev)
- phpdocumentor/phpdocumentor: 2.*
- phpunit/phpunit: 3.7.*
This package is auto-updated.
Last update: 2022-02-01 12:34:21 UTC
README
Laravel 4 库,用于调用 http://freegeoip.net/ API。
与其他所有包不同,它不需要您在文件系统中安装 geoip 数据库,这个库调用免费服务,所以您不必担心在您的服务器上下载和维护 Maxmind 的 geoip 数据。
只需安装包,添加配置,即可使用!
需求
- PHP >= 5.3.7
- cURL 扩展
安装
composer require buonzz/laravel-4-freegeoip:dev-master
在 config/app.php 中添加服务提供者和外观
服务提供者
Buonzz\GeoIP\Laravel4\ServiceProviders\GeoIPServiceProvider
外观
'GeoIP' => 'Buonzz\GeoIP\Laravel4\Facades\GeoIP',
配置
此库支持可选配置。
要开始,首先发布包配置文件
$ php artisan config:publish buonzz/laravel-4-freegeoip
freegeopipURL:定义 FreeGeoIP API 的 URL。使用 HTTPS 或不使用。默认为http://www.freegeoip.net/json/。timeout:定义调用 FreeGeoIP API 时的超时时间(秒)。默认为 30。
使用
获取访客的国家
GeoIP::getCountry(); // returns "United States"
获取访客的国家代码
GeoIP::getCountryCode(); // returns "US"
获取访客的地区
GeoIP::getRegion(); // returns "New York"
获取访客的地区代码
GeoIP::getRegionCode(); // returns "NY"
获取访客的城市
GeoIP::getCity(); // returns "Buffalo"
获取访客的邮编
GeoIP::getZipCode(); // returns "14221"
获取访客的纬度
GeoIP::getLatitude(); // returns "42.9864"
获取访客的经度
GeoIP::getLongitude(); // returns "-78.7279"
获取访客的地铁代码
GeoIP::getMetroCode(); // returns "514"
获取访客的地区代码
GeoIP::getAreaCode(); // returns "716"
鸣谢
- Alexandre Fiori 为其出色的 http://freegeoip.net 网络API
- MaxMind 提供数据