interaction-design-foundation / laravel-geoip
支持多种地理定位服务。
3.6.0
2024-08-07 12:12 UTC
Requires
- php: ^8.1
- illuminate/cache: ^10.0 || ^11.0
- illuminate/console: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
- monolog/monolog: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.50
- geoip2/geoip2: ^3.0
- orchestra/testbench: ^8.8 || ^9.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5 || ^11.0
- squizlabs/php_codesniffer: ^3.9
- vimeo/psalm: ^5.22
Suggests
- geoip2/geoip2: Required to use the MaxMind database or web service with GeoIP (~2.1).
- monolog/monolog: Allows for storing location not found errors to the log
- dev-main
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.1
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- dev-alies-dev-patch-1
- dev-defaultLocationResolver
- dev-refactor-services
- dev-add-types
This package is auto-updated.
Last update: 2024-09-07 12:40:58 UTC
README
根据网站访客的IP地址确定其地理位置和货币。
关于此分支
由于原项目几乎不再活跃维护,我们已从 torann/geoip
分支出来。此分支仅支持现代PHP版本(8.0+),维护良好并包含额外功能
- 支持现代Laravel和PHP版本
- 更好的类型(本地和PHPDoc)
- 更安全的文件和网络功能
- 可以前缀缓存键(
cache_prefix
配置选项) - 可以使用环境变量
GEOIP_SERVICE
更改服务 - 更新后的货币
- 更可预测的异常
但不用担心,我们遵循SemVer 2.0。包迁移过程非常简单,请参阅 迁移文档。
安装
从命令行运行
composer require interaction-design-foundation/laravel-geoip
发布配置
从项目的根目录运行此命令
php artisan vendor:publish --provider="InteractionDesignFoundation\GeoIP\GeoIPServiceProvider" --tag=config
配置
配置文件中的两个主要选项的简要说明。要了解更多信息,请打开 config/geoip.php
文件。
服务配置
为了简化并保持整洁,所有必需的第三方composer包都将单独安装。
有关进一步配置选项,请参阅 服务页面。
缓存配置
GeoIP使用Laravel的默认缓存来存储查询的IP位置。这样做是为了减少对所选服务的调用次数,因为其中一些服务有限制。
选项
all
缓存所有位置some
仅缓存请求的用户none
完全禁用缓存
使用
使用此包有一些选项
geoip()
辅助函数InteractionDesignFoundation\GeoIP\Facades\GeoIP
门面
geoip()->getLocation('27.974.399.65'); // Get the location from the provided IP. geoip()->getClientIP(); // Will return the user IP address.
位置对象的示例
\InteractionDesignFoundation\GeoIP\Location {[ 'ip' => '1.1.1.1', 'iso_code' => 'US', 'country' => 'United States', 'city' => 'New Haven', 'state' => 'CT', 'state_name' => 'Connecticut', 'postal_code' => '06510', 'lat' => 41.28, 'lon' => -72.88, 'timezone' => 'America/New_York', 'continent' => 'NA', 'currency' => 'USD', 'default' => false, ]}
Location
类实现了 \ArrayAccess
接口,这意味着您可以使用对象和数组访问方式访问位置对象的属性
$location = geoip()->getLocation(); $city = $location->city; // The same as: $city = $location['city'];
Artisan
某些服务需要下载和使用本地数据库通过IP地址检测位置。有一个控制台命令可以下载/更新数据库
php artisan geoip:update
某些缓存驱动程序提供清除缓存位置的选项
php artisan geoip:clear
变更日志
请参阅 发布 了解最近更改的详细信息。
贡献
请参阅 贡献 了解详细信息。
贡献
自项目启动以来,许多人已经为此项目做出了贡献。
感谢