zoukankan      html  css  js  c++  java
  • Laravel根据Ip获取国家,城市信息

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

    1、安装:

    composer require geoip2/geoip2:~2.0
    

    2、用法:

    <?php
    require_once 'vendor/autoload.php';
    use GeoIp2DatabaseReader;
    
    // 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 . "
    "); // 'US'
    print($record->country->name . "
    "); // 'United States'
    print($record->country->names['zh-CN'] . "
    "); // '美国'
    
    print($record->mostSpecificSubdivision->name . "
    "); // 'Minnesota'
    print($record->mostSpecificSubdivision->isoCode . "
    "); // 'MN'
    
    print($record->city->name . "
    "); // 'Minneapolis'
    
    print($record->postal->code . "
    "); // '55455'
    
    print($record->location->latitude . "
    "); // 44.9733
    print($record->location->longitude . "
    "); // -93.2323
    

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

  • 相关阅读:
    第一次冲刺站立会议03
    第二次冲刺计划会议
    梦断代码阅读笔记02
    学习进度12
    个人项目——找水王
    学习进度11
    梦断代码阅读笔记01
    学习进度10
    学习进度09
    第一次冲刺个人博客10
  • 原文地址:https://www.cnblogs.com/lxwphp/p/9233403.html
Copyright © 2011-2022 走看看