PHP code example of sypex / geo

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

    

sypex / geo example snippets


$filepath = 'SxGeo.dat';
$geo = new Geo($filepath); // by default SxGeo.dat
$geo = new SxGeo($filepath, Mode::BATCH | Mode::MEMORY); // the fastest way

// Get country (SxGeo Country)
//
// 2-letter ISO code of country
$country = $geo->getCountry($ip);
// number of country
$geo->getCountryId($ip);

// get city (SxGeo City, SxGeo City Max)
//
// short information, without region name, country and timezone
$geo->getCity($ip);
// full city information
$geo->getCityFull($ip);
// calls getCountry or getCity depending on the type of base
$city = $geo->get($ip);

// free resource
unset($geo);