hamidreza2005 / php-ip
一个用于通过IP地址获取客户端位置的PHP包
v1.0.1
2020-09-23 16:38 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ~7
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-29 05:55:53 UTC
README
此包可以帮助您在PHP中通过IP地址查找客户端位置🚀
安装
您可以通过Composer安装此包
composer require hamidreza2005/php-ip
用法
首先,您必须初始化您的驱动程序
use hamidreza2005\phpIp\Geojs; use hamidreza2005\phpIp\Ipinfo; use hamidreza2005\phpIp\Ipapi; $ip = new Geojs($DebugMode,$IP); //visit https://www.geojs.io/ $ip = new Ipapi(API_TOKEN,$DebugMode,$IP); // visit https://www.ipapi.com/ $ip = new Ipinfo(API_TOKEN,$JSON_FILE_PATH,$DebugMode,$IP); // visit https://www.ipinfo.io/
然后,您可以使用驱动程序的方法
$ip->countryCode() // return country Code e.g DE $ip->all() // return all Details about client's ip $ip->coordinates() // return client's coordinates $ip->ip() // return all client's ip $ip->country() // return all client's country full name e.g Germany
注意:由于每个驱动程序的结构不同,您应该使用所有方法来访问IP的详细信息
在ipinfo驱动程序中获取国家全名
正如您所知,ipinfo结构中没有国家全名。因此,如果您想使用ipinfo驱动程序并需要国家全名(例如:法国),您可以创建一个JSON文件,并像这样设置$JSON_FILE_PATH
:
<?php use hamidreza2005\phpIp\Ipapi; $ip = new Ipinfo(API_TOKEN,"./file/path.json")
例如,path.json
文件应该是这样的:
{ "US": "United State", "DE": "Germany" }
现在,您可以通过$ip->country()
在ipinfo驱动程序中获取国家全名
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
🙋 贡献
如果您发现了一个问题,或者有更好的实现方式,请随时提交一个issue或pull request。