PHP code example of itxq / ip-php
1. Go to this page and download the library: Download itxq/ip-php library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itxq / ip-php example snippets
use itxq\util\IP;
// 实例化时可指定IP数据库文件路径
$IP = new IP();
// 获取全部信息(返回数组)eg:
// array(4) {
// ["begin_ip"]=>
// string(8) "1.80.0.0"
// ["end_ip"]=>
// string(12) "1.80.155.255"
// ["address"]=>
// string(18) "陕西省西安市"
// ["area"]=>
// string(6) "电信"
// }
$ipInfoAll = $IP->getIpInfo('1.80.96.23', IP::IP_INFO_ALL);
// 只获取地址信息(返回字符串)eg:贵州省贵阳市南明区电信
$ipInfo = $IP->getIpInfo('1.80.96.23', IP::IP_INFO);
// 获取IP所在IP段(返回数组)eg:['1.80.0.0','1.80.155.255']
$ipRange = $IP->getIpInfo('1.80.96.23', IP::IP_RANGE);
// 引入扩展(具体路径请根据你的目录结构自行修改)