PHP code example of maxmind-db / reader

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

    

maxmind-db / reader example snippets






use MaxMind\Db\Reader;
$reader = new Reader('example.mmdb');


MaxMind\Db\Reader;

$ipAddress = '24.24.24.24';
$databaseFile = 'GeoIP2-City.mmdb';

$reader = new Reader($databaseFile);

// get returns just the record for the IP address
print_r($reader->get($ipAddress));

// getWithPrefixLen returns an array containing the record and the
// associated prefix length for that record.
print_r($reader->getWithPrefixLen($ipAddress));

$reader->close();
bash
curl -sS https://getcomposer.org/installer | php
bash
dnf install php-maxminddb
bash
yum install php-maxminddb