testingmic/geoip2country

There is no license information available for the latest version (v2.3) of this package.

Get the current visitor IP Address and determine the country, city, latitude, longitude, and ISP

v2.3 2024-12-14 05:03 UTC

This package is auto-updated.

Last update: 2025-06-15 11:26:45 UTC


README

An IP address helps you identify visitors geographical location.

A PHP IP Address Geolocation library to help you identify visitors geographical location.

Requirements

  • pdo_sqlite (runtime deps)
  • php_curl (for update only)

Installation And Initialisation :

These instructions will get you a copy of the project up and running on your local machine. there are two options:

  • Using Composer installer(Recommended) by typing the following command:
composer require testingmic/geoip2country

Usage: (using Composer autoloader)

require __DIR__ . '/vendor/autoload.php';

try
{
    $IpAddressGeo = new testingmic\IpAddressGeoLocation();

} catch (\Throwable $th) {
    trigger_error($th->getMessage(), E_USER_ERROR);
}

Getting Country code from given IP address:

    $ipAddress_1='37.140.250.97';

    echo '<pre>';
    print_r($IpAddressGeo->resolve($ipAddress_1));

    Array
    (
        [start] => 629996032
        [end] => 629996288
        [country_code] => UA
        [country_name] => United States
        [continent_code] => NA
        [city] => Alexandria
        [latitude] => 38.8031
        [longitude] => -77.0388
    )

Getting current visitor Country code (auto detect his IP address):

    echo '<pre>';
    print_r($IpAddressGeo->resolve());  /** resolve() method called without any argument */