PHP code example of macromindonline / geoip

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

    

macromindonline / geoip example snippets


PulkitJalan\GeoIP\GeoIPServiceProvider::class

'GeoIP' => PulkitJalan\GeoIP\Facades\GeoIP::class



use PulkitJalan\GeoIP\GeoIP

$geoip = new GeoIP();

$lat = $geoip->getLatitude(); // 51.5141
$lon = $geoip->getLongitude(); // -3.1969

$config = [
    'driver' => 'freegeoip',
    'freegeoip' => [
        'secure' => true,
    ],
];

$config = [
    'driver' => 'freegeoip',
    'freegeoip' => [
        'url' => 'freegeoip.example.com', // or with a port (freegeoip.example.com:8080)
        'secure' => true, // or false
    ],
];

$config = [
    'driver' => 'ip-api',
    'ip-api' => [
        'key' => 'YOUR IP-API KEY',

        // optionally set secure (https) connection (default: false)
        'secure' => true
    ],
];

$config = [
    'driver' => 'maxmind',
    'maxmind' => [
        'database' => '/path/to/database.mmdb',
    ],
];

$config = [
    'driver' => 'maxmind',
    'maxmind' => [
        'user_id' => 'YOUR MAXMIND USER ID',
        'license_key' => 'YOUR MAXMIND LICENSE KEY'
    ],
];

$config = [
    'driver' => 'telize',
    'telize' => [
        'key' => 'YOUR IP-API KEY',
    ],
];

$geoip->setIp('127.0.0.1');

// Laravel
GeoIP::setIp('127.0.0.1');

$geoip->getLatitude();

// Laravel
GeoIP::getLatitude();

$geoip->getLongitude();

// Laravel
GeoIP::getLongitude();

$geoip->getCity();

// Laravel
GeoIP::getCity();

$geoip->getCountry();

// Laravel
GeoIP::getCountry();

$geoip->getCountryCode();

// Laravel
GeoIP::getCountryCode();

$geoip->getRegion();

// Laravel
GeoIP::getRegion();

$geoip->getRegionCode();

// Laravel
GeoIP::getRegionCode();

$geoip->getPostalCode();

// Laravel
GeoIP::getPostalCode();

$geoip->getTimezone();

// Laravel
GeoIP::getTimezone();

$geoip->getIsp();

// Laravel
GeoIP::getIsp();

$geoip->get(); // returns array

// Laravel
GeoIP::get(); // returns array

$geoip->getRaw(); // different drivers will return different data types

// Laravel
GeoIP::getRaw(); // different drivers will return different data types



use PulkitJalan\GeoIP\GeoIPUpdater

$config = [
    'driver' => 'maxmind',
    'maxmind' => [
        'database' => '/path/to/database.mmdb',
    ],
];

$geoipUpdater = new GeoIPUpdater($config);
$geoipUpdater->update();