PHP code example of div / yii2-geoip

1. Go to this page and download the library: Download div/yii2-geoip 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/ */

    

div / yii2-geoip example snippets


'components' => [
    ...
    'geo' => [
        'class' => 'div\geoip\Geo',
        'cityClass' => 'app\models\City' // модель города
    ],
],

// определение города по текущему адресу
$city = Yii::$app->geo->getCity();
echo $city->name;

// определение города по любому ip
$city = Yii::$app->geo->getCity('123.123.123.123');
echo $city->name;

// получение гео данных по ip
$data = Yii::$app->geo->getData();
/*
Array
(
    [country] => RU
    [city] => Москва
    [region] => Москва
    [district] => Центральный федеральный округ
    [lat] => 55.000000
    [lng] => 37.000000
)
*/