PHP code example of kubrey / geoservice

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

    

kubrey / geoservice example snippets


php composer.phar init



use GeoServices\GeoService;
use GeoServices\GeoException;

$g = new GeoService();
try {
    //set maxmind v2  absolute path to mmdb file(if you want to use this method)
    $g->setMaxmindDb(dirname(__FILE__) . '/GeoLite2-City.mmdb');
    //set maxmind-legacy  absolute path to dat file(if you want to use this method)
    $g->setMaxmindOldDb(dirname(__FILE__).'/GeoLiteCity.dat');
    $data = $g->lookup('95.153.74.242');
    var_dump($data->city);
} catch (GeoException $ex) {
    echo $ex->getMessage();
}

$g->maxmind = 1;//run first
$g->ipgeobaseru = false;//do not use
$g->ipinfo = 3;

$g->isCityRequired = false; - поиск города не обязателен

$g->setGlobalTimeout(5000);

$g->setRequestTimeout(1000);

/usr/bin/php vendor/phpunit/phpunit/phpunit --colors --bootstrap vendor/autoload.php tests