PHPackages                             playtini/geoip - 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. playtini/geoip

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

playtini/geoip
==============

Simple GeoIP Client for MaxMind and IP2Location Databases

1.2(6mo ago)01.6k↓50%GPL-3.0-onlyPHPPHP ^8.1CI passing

Since Jun 27Pushed 6mo agoCompare

[ Source](https://github.com/playtini/geoip)[ Packagist](https://packagist.org/packages/playtini/geoip)[ RSS](/packages/playtini-geoip/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (10)Used By (0)

GeoIP Client
============

[](#geoip-client)

[![](https://camo.githubusercontent.com/64bfadde47354bb40feb2732e0e5e8e7c4668ae6856508a04327c9599938fc2d/687474703a2f2f706f7365722e707567782e6f72672f706c617974696e692f67656f69702f76657273696f6e)](https://packagist.org/packages/playtini/geoip)[![](https://camo.githubusercontent.com/d395dbec966d4f02b596a236f6dc89f441d74e9450e20037a583fe39da6df27f/687474703a2f2f706f7365722e707567782e6f72672f706c617974696e692f67656f69702f726571756972652f706870)](https://packagist.org/packages/playtini/geoip)[![](https://camo.githubusercontent.com/9d5bf00fcd9c3126d445164ca5490c56f905e769e297ab6e53b7f69460e0d67a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706c617974696e692f67656f6970)](https://packagist.org/packages/playtini/geoip)[![](https://camo.githubusercontent.com/669a913d008d5db4209da0e303b5395bf5477f05d5c5b66ed9a5bec73a239036/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f706c617974696e692f67656f69702f6d61696e)](https://camo.githubusercontent.com/669a913d008d5db4209da0e303b5395bf5477f05d5c5b66ed9a5bec73a239036/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f706c617974696e692f67656f69702f6d61696e)[![](https://camo.githubusercontent.com/b91660b9207d30b8f13d7bdcffa9c769023ce5a216103dc94ee56dfcd9f28166/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706c617974696e692f67656f69702f746573742e79616d6c3f6272616e63683d6d61696e)](https://camo.githubusercontent.com/b91660b9207d30b8f13d7bdcffa9c769023ce5a216103dc94ee56dfcd9f28166/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706c617974696e692f67656f69702f746573742e79616d6c3f6272616e63683d6d61696e)

Maintainer
----------

[](#maintainer)

This library is created and supported by [Playtini](https://playtini.ua).

We're hiring marketers (FB, Tiktok, UAC, in-app, Google) and developers (PHP, JS): [playtini.ua/jobs](https://playtini.ua/jobs)

Install
-------

[](#install)

```
composer require playtini/geoip
```

Usage
-----

[](#usage)

See `examples/*.php`.

```
use Playtini\GeoIp\GeoIp;

require_once(__DIR__ . '/vendor/autoload.php');

$geoIp = new GeoIp();

echo $geoIp->country('8.8.8.8') . "\n"; // US

print_r($geoIp->city('190.0.0.1'));
/*
    [country] => CO
    [city] => Medellín
    [subdivision] => Antioquia
    [subdivision1] => Antioquia
    [subdivision2] =>
    [subdivision3] =>
    [subdivision_code] => ANT
    [postal] => 050021
    [accuracy_radius] => 10
    [latitude] => 6.2529
    [longitude] => -75.5646
    [timezone] => America/Bogota
 */

echo $geoIp->maxMindCountry('190.0.0.1') . "\n"; // CO

print_r($geoIp->maxMindCity('190.0.0.1'));
/*
    [country] => CO
    [city] => Medellín
    [subdivision] => Antioquia
    [subdivision1] => Antioquia
    [subdivision2] =>
    [subdivision3] =>
    [subdivision_code] => ANT
    [postal] => 050021
    [accuracy_radius] => 10
    [latitude] => 6.2529
    [longitude] => -75.5646
    [timezone] => America/Bogota
 */

print_r($geoIp->maxMindAsn('190.0.0.1'));
/*
    [org] => EPM Telecomunicaciones S.A. E.S.P.
    [num] => 13489
    [net] => 190.0.0.0/18
*/

echo $geoIp->ip2LocationCountry('190.0.0.1') . "\n"; // CO

echo $geoIp->ip2LocationProxyType('190.0.0.1') . "\n"; // -
echo $geoIp->ip2LocationProxyType('1.2.3.4') . "\n"; // VPN
echo $geoIp->ip2LocationProxyType('8.8.8.8') . "\n"; // DCH
```

If your GeoIP files aren't named by default or aren't in the dir `/usr/share/GeoIP/` then pass arguments to constructors.

### Priority

[](#priority)

IP2Location database has priority for methods `country`, `city`:

- country - if IP2Location data is not empty - don't look up MaxMind
- city - if IP2Location country differs from MaxMind - use IP2Location country and empty city

If you have guesses which countries may IP be from then you can pass the second argument `array $preferredCountries`. Then even if IP2Location country differs from MaxMind but MaxMind returns country from preferred then MaxMind country will be used.

```
echo $geoIp->maxMindCountry('80.231.192.1') . "\n"; // CA
echo $geoIp->ip2LocationCountry('80.231.192.1') . "\n"; // DZ

echo $geoIp->country('80.231.192.1') . "\n"; // DZ - IP2Location has higher priority

echo $geoIp->country('80.231.192.1', ['BR', 'MX']) . "\n"; // DZ
// IP2Location still has higher priority, MaxMind country is not among preferred countries

echo $geoIp->country('80.231.192.1', ['CA', 'AU']) . "\n"; // CA
// MaxMind country is among preferred countries; it is used instead of different IP2Location country
```

Symfony
-------

[](#symfony)

Add to `config/services.yaml`

```
imports:
    - { resource: '../vendor/playtini/geoip/config/config.yaml' }
```

You can copy config to your .yaml-files without import and tune for your needs.

Add env `GEOIP_DIR` with all your GeoIP database files. Default - `%kernel.project_dir%/data/geoip`

Use with autowire

```
/**
 * @Route("/test", name="test")
 */
public function test(GeoIp $geoIp): Response
{
    dd($geoIpParser->country('1.1.1.1'));
}

```

`GeoIpExtension` is optional to add but if you added it you have Twig filters:

- `domain_ip`: convert domain name or IP to IP - `'google.com'|domain_ip`, `'1.1.1.1'|domain_ip`
- `ip_country_code`: convert IP to country code - `'1.1.1.1'|ip_country_code` - US, AU, ...
- `ip_flag`: convert IP to HTML with flag - `'1.1.1.1'|ip_flag`
- `country_code_flag`: convert country code to HTML with flag - `'CA'|country_code_flag`

To use flags copy `public/css/flags.css` and `public/img/flags.png` to your public folder.

Add to `base.html.twig` or other template:

```

```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance66

Regular maintenance activity

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Every ~60 days

Recently: every ~120 days

Total

9

Last Release

201d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/df3e7060fb5777768e7bb133e98b1e7dfcc788f25fe6dc445acf7036da5c0c3e?d=identicon)[luchaninov](/maintainers/luchaninov)

---

Top Contributors

[![luchaninov](https://avatars.githubusercontent.com/u/3829796?v=4)](https://github.com/luchaninov "luchaninov (9 commits)")

---

Tags

clientproxygeoipmaxmindgeoip2countrycityip2locationplaytini

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/playtini-geoip/health.svg)

```
[![Health](https://phpackages.com/badges/playtini-geoip/health.svg)](https://phpackages.com/packages/playtini-geoip)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

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

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[pulkitjalan/ip-geolocation

IP Geolocation Wrapper with Laravel Support

89164.9k1](/packages/pulkitjalan-ip-geolocation)[dipeshsukhia/laravel-country-state-city-data

Country State City Data Provider

8230.8k](/packages/dipeshsukhia-laravel-country-state-city-data)

PHPackages © 2026

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