PHP code example of sablesoft / yii2-geoip

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

    

sablesoft / yii2-geoip example snippets


    'components' => [
        'geoip'   => [
            'class'      => 'sablesoft\geoip\GeoIP',
            'dbPath'     => '/path/to/your/geoip/database'
        ]
    ]

$ip = "52.141.159.163";
/** @var \sablesoft\geoip\IpData $ipData */
$ipData = \Yii::$app->geoip->get($ip);
$country = $ipData->countryName;
$city   = $ipData->cityName;
$code = $ipData->countryCode;

$default = false;
$path = "some.path.in.ip.data.array";
$someData = $ipData->get($path, $default);