Laravel根据Ip获取国家,城市信息

https://blog.csdn.net/zhezhebie/article/details/79097133

1、安装:

composer require geoip2/geoip2:~2.0

 

2、用法:

city('128.101.101.101');

print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '美国'

print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'

print($record->city->name . "\n"); // 'Minneapolis'

print($record->postal->code . "\n"); // '55455'

print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323

更多参考信息:
https://github.com/maxmind/GeoIP2-php

你可能感兴趣的:(Laravel根据Ip获取国家,城市信息)