yii2-geoip

Yii 2 GeoIP 扩展。返回当前或指定 IP 的国家、城市、纬度、经度(使用 MaxMind 的 GeoIP2 数据库)。「Yii 2 GeoIP extension. Returns country, city, lat, lng of current or specified IP (uses MaxMind's GeoIP2 databases)」

Github星跟蹤圖

Yii 2 GeoIP extension

Latest Stable Version Total Downloads Build Status HHVM Status CodeClimate

Provides information about geographical location of user by IP address.

Currently available:

  • Country
  • City
  • Latitude, Longitude
  • Country ISO Code

Install

Run

$ php composer.phar require lysenkobv/yii2-geoip "~1.0"

OR

add to your composer.json

{
    "require": {
        "lysenkobv/yii2-geoip": "~1.0"
    }
}

and run

$ php composer update

Usage

Like component

<?php

$config = [
    ...
    'components' => [
        'geoip' => ['class' => 'lysenkobv\GeoIP\GeoIP'],
    ]
    ...
];

somewhere in code

$ip = Yii::$app->geoip->ip(); // current user ip

$ip = Yii::$app->geoip->ip("208.113.83.165");

$ip->city; // "San Francisco"
$ip->country; // "United States"
$ip->location->lng; // 37.7898
$ip->location->lat; // -122.3942
$ip->isoCode; // "US"

Like object directly somewhere in your application

$geoip = new \lysenkobv\GeoIP\GeoIP();
$ip = $geoip->ip("208.113.83.165");

$ip->city; // "San Francisco"
$ip->country; // "United States"
$ip->location->lng; // 37.7898
$ip->location->lat; // -122.3942
$ip->isoCode;  // "US"

Provide a custom database (for example, if you own a licence)

<?php

$config = [
    ...
    'components' => [
        'geoip' => [
            'class' => 'lysenkobv\GeoIP\GeoIP',
            'dbPath' => Yii::getAlias('@example/maxmind/database/city.mmdb')
        ],
    ]
    ...
];

Thanks to davicrystal, krukru


This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com

主要指標

概覽
名稱與所有者lysenkobv/yii2-geoip
主編程語言C#
編程語言PHP (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2017-10-20 01:08:38
推送於2022-12-08 00:57:54
最后一次提交2021-02-04 16:28:25
發布數0
用户参与
星數525
關注者數23
派生數49
提交數78
已啟用問題?
問題數23
打開的問題數11
拉請求數27
打開的拉請求數5
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?