码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-06-27 14:05:29      阅读:962      评论:0      收藏:0      [点我收藏+]

标签:state   min   oss   eth   ted   art   信息   div   end   

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

1、安装:

composer require geoip2/geoip2:~2.0

 

2、用法:

<?php
require_once ‘vendor/autoload.php‘;
use GeoIp2\Database\Reader;

// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader(‘/usr/local/share/GeoIP/GeoIP2-City.mmdb‘);

// Replace "city" with the appropriate method for your database, e.g.,
// "country".
$record = $reader->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获取国家,城市信息

标签:state   min   oss   eth   ted   art   信息   div   end   

原文地址:https://www.cnblogs.com/lxwphp/p/9233403.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!