PHP code example of lostlink / laravel-geoip

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

    

lostlink / laravel-geoip example snippets


LostLink\GeoIP\GeoIPServiceProvider::class

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



use LostLink\GeoIP\GeoIP

$geoip = new GeoIP();

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

$config = [
    'driver' => 'ipstack',
    'ipstack' => [
        'key' => 'YOUR IPSTACK KEY',
        'secure' => true, // (optional) use https
    ],
];

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

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

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

$config = [
    'driver' => 'telize',
    'telize' => [
        'key' => 'YOUR TELIZE 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 LostLink\GeoIP\GeoIPUpdater

$config = [
    'driver' => 'maxmind_database',
    'maxmind_database' => [
        'database' => '/path/to/database.mmdb',
        'license_key' => 'YOUR MAXMIND LICENSE KEY'
    ],
];

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