lithiumdev / larageo-plugin
一个使用 geoPlugin 网络服务从 IP 获取信息的 Laravel 扩展包。
v1.1.2
2021-01-31 21:38 UTC
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: >=6.0
- illuminate/support: >=5.0
This package is auto-updated.
Last update: 2024-09-05 11:14:00 UTC
README
Laravel 5+ 地理 IP 包
来自 Lithium Hosting
我们总是欢迎 pull requests,请随意将其变为自己的或帮助我们使其更好。
版权
(c) Lithium Hosting, llc
许可证
此库采用 MIT 许可证;您可以在文件 /LICENSE 中找到许可证的完整副本。
要求
- Laravel 5.2+
- php 5.5.9+
- 了解 Laravel 和 php
描述
一个使用 geoPlugin 网络服务从 IP 获取信息的 Laravel 扩展包。它将 IP 信息存储在缓存中,并在一周后过期。
安装
通过 Composer 安装此包。将以下内容添加到您的 composer.json 文件中:
"lithiumdev/larageo-plugin": "~1.0"
然后,运行 Composer 更新命令
$ composer update
将服务提供者添加到 app/config/app.php 文件中的 providers 数组中。
'providers' => array( // ... LithiumDev\LaraGeo\ServiceProvider::class, ),
在相同的文件 config/app.php
中添加别名
'aliases' => array( //... 'LaraGeo' => LithiumDev\LaraGeo\Facade::class, ),
用法
您可以指定一个 IP
$info = LaraGeo::getInfo('177.34.13.248'); // get info from a IP var_dump($info);
或者不指定任何参数使用它
$info = LaraGeo::getInfo(); // get info from the IP of the user accessing the page var_dump($info);
这是输出结果
object(stdClass)[155] public 'geoplugin_request' => string '177.34.13.248' (length=13) public 'geoplugin_status' => int 200 public 'geoplugin_credit' => string 'Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\'http://www.maxmind.com\'>http://www.maxmind.com</a>.' (length=145) public 'geoplugin_city' => string 'Campo Grande' (length=12) public 'geoplugin_region' => string 'Mato Grosso do Sul' (length=18) public 'geoplugin_areaCode' => string '0' (length=1) public 'geoplugin_dmaCode' => string '0' (length=1) public 'geoplugin_countryCode' => string 'BR' (length=2) public 'geoplugin_countryName' => string 'Brazil' (length=6) public 'geoplugin_continentCode' => string 'SA' (length=2) public 'geoplugin_latitude' => string '-20.450001' (length=10) public 'geoplugin_longitude' => string '-54.616699' (length=10) public 'geoplugin_regionCode' => string '11' (length=2) public 'geoplugin_regionName' => string 'Mato Grosso do Sul' (length=18) public 'geoplugin_currencyCode' => string 'BRL' (length=3) public 'geoplugin_currencySymbol' => string 'R$' (length=10) public 'geoplugin_currencySymbol_UTF8' => string 'R$' (length=2) public 'geoplugin_currencyConverter' => float 2.383
另一个有用的示例:您还可以在一次调用中返回一个字段,例如 city
$userCity = LaraGeo::getInfo()->geoplugin_city; // get the city from the user IP var_dump($userCity);
输出
string 'Campo Grande' (length=12)
更多信息
如果您想了解更多关于 geoPlugin 网络服务的信息,请点击这里。