PHP code example of xiaopig123456 / yii2-ip2location
1. Go to this page and download the library: Download xiaopig123456/yii2-ip2location 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/ */
xiaopig123456 / yii2-ip2location example snippets
use \wsl\ip2location\Ip2Location;
// 查询ip
$ipAddress = Ip2Location::getIpAddress();
echo $ipAddress;
// 8.8.8.8
// 根据查询地址
$locationModel = Ip2Location::getIpAddress($ipAddress);
print_r($locationModel->toArray());
// Array
// (
// [country] => 美国
// [province] => null
// [city] => null
// [description] => 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器
// )