PHP code example of kostikpenzin / yii2-geoip

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

    

kostikpenzin / yii2-geoip example snippets



    $geo = new \kostikpenzin\geoip\Geoip();

    // get by remote IP
    $geo->get();                // also returned geo data as array
    echo $geo->ip,'<br>';
    echo $geo->ipAsLong,'<br>';
    var_dump($geo->country); echo '<br>';
    var_dump($geo->region);  echo '<br>';
    var_dump($geo->city);    echo '<br>';

    // get by custom IP
    print_r($geo->get('88.200.214.22'));


array (
  'ip' => '135.181.47.216',
  'city' =>
  array (
    'id' => 658225,
    'lat' => 60.16952,
    'lon' => 24.93545,
    'name_ru' => 'Хельсинки',
    'name_en' => 'Helsinki',
    'name_de' => 'Helsinki',
    'name_fr' => 'Helsinki',
    'name_it' => 'Helsinki',
    'name_es' => 'Helsinki',
    'name_pt' => 'Helsínquia',
    'okato' => '',
    'vk' => 0,
    'population' => 558457,
    'tel' => '',
    'post' => '',
  ),
  'region' =>
  array (
    'id' => 828987,
    'lat' => 60.83,
    'lon' => 26,
    'name_ru' => 'Южная Финляндия',
    'name_en' => 'Southern Finland Province',
    'name_de' => 'Südfinnland (Provinz)',
    'name_fr' => 'Finlande méridionale',
    'name_it' => 'Finlandia meridionale',
    'name_es' => 'Finlandia Meridional',
    'name_pt' => 'Finlândia Meridional',
    'iso' => 'FI-ES',
    'timezone' => 'Europe/Helsinki',
    'okato' => '',
    'auto' => '',
    'vk' => 0,
    'utc' => 2,
  ),
  'country' =>
  array (
    'id' => 69,
    'iso' => 'FI',
    'continent' => 'EU',
    'lat' => 64,
    'lon' => 26,
    'name_ru' => 'Финляндия',
    'name_en' => 'Finland',
    'name_de' => 'Finnland',
    'name_fr' => 'Finlande',
    'name_it' => 'Finlandia',
    'name_es' => 'Finlandia',
    'name_pt' => 'Finlândia',
    'timezone' => 'Europe/Helsinki',
    'area' => 337030,
    'population' => 5244000,
    'capital_id' => 658225,
    'capital_ru' => 'Хельсинки',
    'capital_en' => 'Helsinki',
    'cur_code' => 'EUR',
    'phone' => '358',
    'neighbours' => 'NO,RU,SE',
    'vk' => 207,
    'utc' => 2,
  ),
  'error' => '',
  'request' => -1,
  'created' => '2021.03.18',
  'timestamp' => 1616099629,
)


php composer.phar