通过 IP,获取该 IP 所在的位置,例如通过 ip:27.196.21.222
可以获得 **山东聊城
。
IP 数据库更新于:2018年07月02日,数据来源于 http://www.ipip.net/ ,IP 数据库由 ipip.net 所有,本项目仅供 php 项目 composer 安装方便使用。
- 不依赖数据库,使用 DATX 格式数据,查询性能高效
- 使用简单,功能专注
- 使用 composer 进行安装管理,方便快捷,随时更新数据库
composer require xdstack/ip2location
使用方法超级简单,只有两个方法,find
和 location
。find 返回数组形式的结果,location 返回字符串形式的结果。
非 Laravel:
<?php
require 'vendor/autoload.php';
use xdstack\ip2location\Ip;
var_dump(Ip::find('27.196.21.222'));
返回结果
array(4) {
[0] => string(6) "**"
[1] => string(6) "山东"
[2] => string(6) "聊城"
[3] => string(0) ""
}
Laravel:
Ip::find('27.196.21.222')
或 Ip::find(Request::getClientIp())
有什么新的想法和建议,欢迎提交 issue 或者 Pull Requests 。
MIT