PHPackages                             nuthouse-cis/ip-location - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nuthouse-cis/ip-location

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nuthouse-cis/ip-location
========================

A simple set of third-party service implementations for determining a geographical location using an IP address

0.1.0(5y ago)07BSD-3-ClausePHPPHP ^7.4|^8.0

Since Apr 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Nuthouse-CIS/IP-Location)[ Packagist](https://packagist.org/packages/nuthouse-cis/ip-location)[ RSS](/packages/nuthouse-cis-ip-location/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (11)Versions (2)Used By (0)

IP Location
===========

[](#ip-location)

A simple set of third-party service implementations for determining a geographical location using an IP address.

This library is based on the screencasts of the knowledge base [Deworker.pro](https://deworker.pro/edu/series/ip-geolocator)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/)

```
composer require nuthouse-cis/ip-location
```

Or add to your `composer.json` file

```
{
  "require": {
    "nuthouse-cis/ip-location": "*"
  }
}
```

Examples
--------

[](#examples)

### Basic usage

[](#basic-usage)

```
require 'vendor/autoload.php';
/** @var $locator \NuthouseCIS\IPLocation\Locator */
$ip = new \NuthouseCIS\IPLocation\Ip('8.8.8.8');
$location = $locator->locate($ip);

if ($location
    && ($location->getCountry()->getIsoAlpha2() === 'US'
        || $location->getCountry()->getIsoAlpha3() === 'USA'
        || $location->getCountry()->getName() === 'United States')
) {
    // Do some stuff
}
```

Also placed JSON decorator:

```
/** @var $location \NuthouseCIS\IPLocation\Location\Location */
$decorator = new \NuthouseCIS\IPLocation\Decorators\LocationJsonDecorator($location);
print json_encode($decorator);
```

### Cache Locator

[](#cache-locator)

This locator using PSR-16 Simple Cache interface for caching result of another implementation of `\NuthouseCIS\IPLocation\Locator`

```
/**
 * @var $simpleCacheIterface \Psr\SimpleCache\CacheInterface
 * @var $adapter \NuthouseCIS\IPLocation\Locator
 */
$locator = new \NuthouseCIS\IPLocation\Locators\CacheLocator(
    $adapter,
    $simpleCacheIterface,
    10 * 60,
    'adapter1-'
);
```

### Mute Locator

[](#mute-locator)

Mute locator catch all `Exceptions` and use implementation of `\NuthouseCIS\IPLocation\Handlers\ErrorHandler` to handle they

```
$errorHandler = new class implements \NuthouseCIS\IPLocation\Handlers\ErrorHandler {
    public function handle(Exception $exception): void
    {
        // Do some stuff with exception
    }
};
/**
 * @var $adapter \NuthouseCIS\IPLocation\Locator
 */
$locator = new \NuthouseCIS\IPLocation\Locators\MuteLocator(
    $adapter,
    $errorHandler
);
```

Also, you can use `\NuthouseCIS\IPLocation\Handlers\PsrLogErrorHandler`

```
/**
 * @var $logger \Psr\Log\LoggerInterface
 */
$errorHandler = new \NuthouseCIS\IPLocation\Handlers\PsrLogErrorHandler(
    $logger,
    \Psr\Log\LogLevel::ERROR
);
```

### Chain Locator

[](#chain-locator)

Chain locator returns the most complete result from all passed implementations of `\NuthouseCIS\IPLocation\Locator`

```
/**
 * @var $adapters \NuthouseCIS\IPLocation\Locator[]
 */
$locator = new \NuthouseCIS\IPLocation\Locators\ChainLocator(
    ...$adapters
);
```

Services
--------

[](#services)

### IpGeoLocation

[](#ipgeolocation)

[IP Geolocation API Documentation](https://ipgeolocation.io/documentation/ip-geolocation-api.html)

```
/**
 * @var $client \Psr\Http\Client\ClientInterface
 * @var $requestFactory \Psr\Http\Message\RequestFactoryInterface
 * @var $apiKey string API Key from your dashboard https://app.ipgeolocation.io/
 * @var $lang string [en, de, ru, ja, fr, cn, es, cs, it]
 * @var $fields null|string[] required fields. Default: ['geo'] - minimum sufficient set of fields
 * @var $excludes null|string[] excluded fields
 * @var $baseUrl string default: https://api.ipgeolocation.io/ipgeo
 * @link https://ipgeolocation.io/documentation/ip-geolocation-api.html
 */
$locator = new \NuthouseCIS\IPLocation\Locators\IpGeoLocationIo\IpGeoLocationIoAdapter(
    $client,
    $requestFactory,
    $apiKey,
    $lang,
    $fields,
    $excludes,
    $baseUrl
);
$location = $locator->locate(new \NuthouseCIS\IPLocation\Ip('8.8.8.8'));
```

### SypexGeo

[](#sypexgeo)

[SypexGeo Documentation](https://sypexgeo.net/ru/docs/)

#### Database file

[](#database-file)

```
/**
 * @var $filePath string path to SypexGeo database file
 * @see https://sypexgeo.net/ru/download/
 */
$sxGeo = new \NuthouseCIS\SxGeo\SxGeo(
    $filePath,
    \NuthouseCIS\SxGeo\SxGeo::SXGEO_BATCH | \NuthouseCIS\SxGeo\SxGeo::SXGEO_MEMORY
);
$locator = new \NuthouseCIS\IPLocation\Locators\SypexGeo\SypexGeoAdapter($sxGeo);
$location = $locator->locate(new \NuthouseCIS\IPLocation\Ip('8.8.8.8'));
```

#### REST API

[](#rest-api)

[SypexGeo REST API Documentation](https://sypexgeo.net/ru/api/)

```
/**
 * @var $client \Psr\Http\Client\ClientInterface
 * @var $requestFactory \Psr\Http\Message\RequestFactoryInterface
 * @var $apiKey null|string API Key [Default: null - free plan]
 * @var $server string endpoint domain [Default: api.sypexgeo.net]
 * @see \NuthouseCIS\IPLocation\Locators\SypexGeo\ApiServer
 * @link https://ipgeolocation.io/documentation/ip-geolocation-api.html
 */
$locator = new \NuthouseCIS\IPLocation\Locators\SypexGeo\SypexGeoApiAdapter(
    $client,
    $requestFactory,
    $server,
    $apiKey
);
$location = $locator->locate(new \NuthouseCIS\IPLocation\Ip('8.8.8.8'));
```

### IP2Location

[](#ip2location)

#### Database file

[](#database-file-1)

[IP2Location Documentation](https://github.com/chrislim2888/IP2Location-PHP-Module)

```
/**
 * @var $filePath string path to IP2Location database file
 * @link https://www.ip2location.com/database/ip2location
 * @link https://lite.ip2location.com/database/ip-country
 */
$db = new \IP2Location\Database($filePath);
/**
 * @var $fields int[] Fields to return
 * @var $requiredFields int[] Required fields. Throws exception, if field empty or not supported
 * If null, copy values from $fields param
 */
$locator = new \NuthouseCIS\IPLocation\Locators\Ip2Location\Ip2LocationAdapter(
    $db,
    $fields,
    $requiredFields
);
$location = $locator->locate(new \NuthouseCIS\IPLocation\Ip('8.8.8.8'));
```

#### API

[](#api)

[IP2Location API Documentation](https://www.ip2location.com/docs/ws1-user-manual.pdf)

```
/**
 * @var $client \Psr\Http\Client\ClientInterface
 * @var $requestFactory \Psr\Http\Message\RequestFactoryInterface
 * @var $apiKey string API Key [Default: null - free plan]
 * @var $lang string
 * @var $package string Web service package of different granularity of return information.
 * Available values: [WS1, ..., WS24]
 * @var $addons string[]  Extra information in addition to the above selected package.
 * Valid value: continent,country,region,city,geotargeting,country_groupings,time_zone_info
 * @var $baseUrl string Endpoint for API [Default: https://api.ip2location.com/v2/]
 * @link https://ipgeolocation.io/documentation/ip-geolocation-api.html
 */
$locator = new \NuthouseCIS\IPLocation\Locators\Ip2Location\Ip2LocationApiAdapter(
    $client,
    $requestFactory,
    $apiKey,
    $package,
    $lang,
    $addons,
    $baseUrl
);
$location = $locator->locate(new \NuthouseCIS\IPLocation\Ip('8.8.8.8'));
```

Testing
-------

[](#testing)

```
# Unit tests:
composer run-script test
# or
$ vendor/bin/phpunit

# Code style:
composer run-script phpcs
# or
$ vendor/bin/phpcs --standard=phpcs.xml

# Static analysis tool (Psalm):
composer run-script psalm
# or
$ vendor/bin/psalm --config=psalm.xml
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1842d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/82461402630da0ecc1881c7685c7d7129469d9e892934f2c91177021dd0b61bf?d=identicon)[Seagull-4auKa](/maintainers/Seagull-4auKa)

---

Top Contributors

[![Seagull-4auKa](https://avatars.githubusercontent.com/u/3746956?v=4)](https://github.com/Seagull-4auKa "Seagull-4auKa (25 commits)")

---

Tags

IPlocationgeocountrycityipinfo

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nuthouse-cis-ip-location/health.svg)

```
[![Health](https://phpackages.com/badges/nuthouse-cis-ip-location/health.svg)](https://phpackages.com/packages/nuthouse-cis-ip-location)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k17](/packages/civicrm-civicrm-core)[kartik-v/yii2-ipinfo

An IP address information display widget for Yii 2.0 with country flag and geo position info.

2832.6k1](/packages/kartik-v-yii2-ipinfo)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[shopware/app-php-sdk

Shopware App SDK for PHP

1577.8k1](/packages/shopware-app-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
