lysenkobv/yii2-geoip

Yii 2 GeoIP extension. Returns country, city, lat, lng of current or specified IP (uses MaxMind's GeoIP2 databases)

Installs: 93 395

Dependents: 6

Suggesters: 0

Security: 0

Stars: 37

Watchers: 5

Forks: 19

Open Issues: 5

Type:yii2-extension

1.0.4 2017-04-25 12:38 UTC

This package is auto-updated.

Last update: 2021-12-07 09:41:28 UTC


README

Latest Stable Version Total Downloads Build Status HHVM Status CodeClimate

I'm no longer want to maintain this repository, if you have interest to do this, please contact me on lysenkobv@gmail.com

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