A library for retrieving location data based on a visitor's IP address.


Keywords
maxmind, geoip, location, cloudflare, psaudio
License
Other

Documentation

PS Audio GeoIP Library

Latest Stable Version License

Requirements

  • PHP >= 7.0.25

Installation

Install via Composer:

composer require psaudio/geoip

Install Manually:

cd path/to/installation/directory/
git clone --depth=1 --branch=v1.1 git@bitbucket.org:psaudioengineering/php-geoip-library.git .
rm -rf .git/
composer install --no-dev

Usage

Instantiate the class by providing it the location of a downloaded and extracted MaxMind database:

$locator = Locator::getInstance('path/to/maxmind/database');

Get the ISO 3166-1 alpha-2 country code by passing the lookup method the IPv4 or IPv6 address and (optionally) the header information set by Cloudflare:

$locator->lookup('50.237.197.203', $_SERVER['HTTP_CF_IPCOUNTRY']);                  // returns 'US'
$locator->lookup('2001:5a8:00:00:00:00:00:00', $_SERVER['HTTP_CF_IPCOUNTRY']);      // returns 'US'
$locator->lookup('23.32.5.108');                                                    // returns 'AU'

Credits