PHP code example of overals / yii2-geoip2

1. Go to this page and download the library: Download overals/yii2-geoip2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

overals / yii2-geoip2 example snippets




$config = [
    ...
    'components' => [
        'geoip2' => [
            'class' => 'overals\GeoIP2\GeoIP2',
            'mmdb' => '@app/components/GeoIP2/GeoLite2-City.mmdb',
            'lng' => 'en', // available languages = 'de', 'en', 'es', 'ja', 'ru', 'zh-CN'
        ],
    ]
    ...
];

$ip = Yii::$app->component->geoip2->getInfoByIP(); // current user ip
$ip = Yii::$app->component->geoip2->getInfoByIP("8.8.8.8");

$ip->continent; // "North America"
$ip->country; // "United States"
$ip->isoCode; // "US"
$ip->subdivisions; // "California"
$ip->city; // "Mountain View"
$ip->location->longitude; // -122.0838
$ip->location->latitude; // 37.386

bash
$ php composer.phar