PHP code example of qbcloud / laravel-geoip2
1. Go to this page and download the library: Download qbcloud/laravel-geoip2 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/ */
qbcloud / laravel-geoip2 example snippets
use QbCloud\Geoip2\Facades\IPQuery;
// 查询 ipv4 或者 ipv6
IPQuery::connect('x.x.x.x');
// 格式化地址
IPQuery::format(['中国', '广东', '广东']); // 中国-广东
IPQuery::format(['中国', '广东', '广州']); // 中国-广东-广州
// 查询IP类型
IPQuery::ipType('x.x.x.x'); // IPv4
// 查询是否是有效IP
IPQuery::isValid('x.x.x.x'); // false
// 或者
use QbCloud\Geoip2\IPQuery;
$client = new IPQuery();
$client->connect('2xx6:4xx0:0:1x3::a0');