PHP code example of pulkitjalan / ip-geolocation

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

    

pulkitjalan / ip-geolocation example snippets


PulkitJalan\IPGeolocation\IPGeolocationServiceProvider::class

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



use PulkitJalan\IPGeolocation\IPGeolocation

$ip = new IPGeolocation();

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

$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' => 'ipstack',
    'ipstack' => [
        'key' => 'YOUR IPSTACK KEY',
        'secure' => true, // (optional) use https
    ],
];

$ip->setIp('127.0.0.1');

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

$ip->getLatitude();

// Laravel
IPGeolocation::getLatitude();

$ip->getLongitude();

// Laravel
IPGeolocation::getLongitude();

$ip->getCity();

// Laravel
IPGeolocation::getCity();

$ip->getCountry();

// Laravel
IPGeolocation::getCountry();

$ip->getCountryCode();

// Laravel
IPGeolocation::getCountryCode();

$ip->getRegion();

// Laravel
IPGeolocation::getRegion();

$ip->getRegionCode();

// Laravel
IPGeolocation::getRegionCode();

$ip->getPostalCode();

// Laravel
IPGeolocation::getPostalCode();

$ip->getTimezone();

// Laravel
IPGeolocation::getTimezone();

$ip->getIsp();

// Laravel
IPGeolocation::getIsp();

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

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

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

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



use PulkitJalan\IPGeolocation\IPGeolocationUpdater

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

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