Skip to content

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

License

Notifications You must be signed in to change notification settings

andrewblake1/yii2-geoip

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii 2 GeoIP extension

Latest Stable Version Build Status HHVM Status CodeClimate

Provides information about geographical location of user by IP address.

Currently available:

  • Country
  • City
  • Latitude, Longitude

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->component->geoip->ip(); // current user ip

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

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

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

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%