PHP code example of labor-digital / max-mind-helpers
1. Go to this page and download the library: Download labor-digital/max-mind-helpers 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/ */
labor-digital / max-mind-helpers example snippets
use LaborDigital\MaxMindHelpers\Downloader;
// This should probably run in a cron job once a day!
$licenseKey = "YOUR LICENSE KEY";
$path = '/path/to/a/writable/directory/to/store/database';
$downloader = new Downloader($licenseKey, $path, new \GuzzleHttp\Client());
// This will check if an update is available based on the md5 hash of the local database
// and download the (~40MB) file only if
use LaborDigital\MaxMindHelpers\Reader;
// Define the path to the stored database
$path = '/path/to/a/writable/directory/to/store/database/library.mmdb';
// Get the reader
$reader = new Reader(new \MaxMind\Db\Reader($path));
// Optional
// Use the PSR-16 Cache interface to cache queries for faster lookups
$cache = new AwesomeCache(); // A class that implements \Psr\SimpleCache\CacheInterface
$reader = new Reader(new \MaxMind\Db\Reader($path), $cache);
// Get the geolocation of an ip
$location = $reader->getLocation('129.200.121.12');
// Result ['latitude' => 0.0, 'longitude' => 0.0];
// Result if query failed: NULL
// Get the geolocation of the current client's ip
$location = $reader->getLocation();
// Result's as above. If you use this at 127.0.0.1 the result will always be NULL
// Get additional information of an ip
$info = $reader->getInformation('129.200.121.12');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.