PHP code example of den67rus / yii2-sypexgeo

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

    

den67rus / yii2-sypexgeo example snippets



    $geo = new \jisoft\sypexgeo\Sypexgeo();

    // 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
    $geo->get('212.42.76.252');


    $geo = new \jisoft\sypexgeo\SxUpdate();
    
    // Custom dir dat files
    // by default Yii::getAlias('@runtime'); or __DIR__ if not Yii Framework
    $geo->updateDir = '/tmp';
    
    // Custom url update
    $geo->cityUrl = 'http://example.com/file.zip';
    $geo->countryUrl = 'http://example.com/file.zip';
    $geo->maxUrl = 'http://example.com/file.zip'; // Be sure to specify the url


    // Update Sypex Geo City file
    $geo->updateCity();
    
    // Update Sypex Geo Country file
    $geo->updateCountry();
    
    // Update Sypex Geo Max file
    // Be sure to specify the url $geo->maxUrl
    $geo->updateMax();
    
    // Update Sypex Geo all file
    // Be sure to specify the url $geo->maxUrl
    $geo->updateAll();
html

Country
 array (
    'id' => 222,
    'iso' => 'UA',
    'continent' => 'EU',
    'lat' => 49,
    'lon' => 32,
    'name_ru' => 'Украина',
    'name_en' => 'Ukraine',
    'timezone' => 'Europe/Kiev',
  ),

Region
 array (
    'id' => 709716,
    'lat' => 48,
    'lon' => 37.5,
    'name_ru' => 'Донецкая область',
    'name_en' => 'Donets\'ka Oblast\'',
    'iso' => 'UA-14',
    'timezone' => 'Europe/Zaporozhye',
    'okato' => '14',
  ),

City
 array (
    'id' => 709717,
    'lat' => 48.023000000000003,
    'lon' => 37.802239999999998,
    'name_ru' => 'Донецк',
    'name_en' => 'Donets\'k',
    'okato' => '14101',
  ),