PHPackages                             ndevs-eu/geo-ip-bundle - 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. ndevs-eu/geo-ip-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

ndevs-eu/geo-ip-bundle
======================

Symfony bundle for Geo IP functionality

v1.0.16(9mo ago)5114MITPHPPHP ^8.2 || ^8.3CI passing

Since Aug 8Pushed 9mo agoCompare

[ Source](https://github.com/ndevs-eu/geo-ip-bundle)[ Packagist](https://packagist.org/packages/ndevs-eu/geo-ip-bundle)[ RSS](/packages/ndevs-eu-geo-ip-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (9)Used By (0)

 [ ![PHPStan Level 9](https://camo.githubusercontent.com/fa7d257d0c5c1cf237ac3490ef3a5561626b17fcb0a8547c01b0bb8746554e60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) ](https://github.com/ndevs-eu/geo-ip-bundle/actions) [ ![CI](https://github.com/ndevs-eu/geo-ip-bundle/actions/workflows/ci.yml/badge.svg) ](https://github.com/ndevs-eu/geo-ip-bundle/actions/workflows/ci.yml) [ ![Latest Stable Version](https://camo.githubusercontent.com/53a727817b047cf1f0abae3973d559283fe5b5e68a560e40722b65c8542d9a1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e646576732d65752f67656f2d69702d62756e646c652e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/ndevs-eu/geo-ip-bundle) [ ![Total Downloads](https://camo.githubusercontent.com/c6c4ef2642dba81a0b8ef1bb654dfca13bee4a0d04a41e3e1db4c93376edfd17/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e646576732d65752f67656f2d69702d62756e646c652e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/ndevs-eu/geo-ip-bundle) [ ![License](https://camo.githubusercontent.com/6932cd1a278d13f1379eb93b32072b7b1b2b766a202b121b3a1b5c00a92c3a59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e646576732d65752f67656f2d69702d62756e646c653f7374796c653d666c61742d737175617265) ](https://github.com/ndevs-eu/geo-ip-bundle/blob/main/LICENSE)

🌍 NDevs GeoIP Bundle
====================

[](#-ndevs-geoip-bundle)

Symfony bundle for detecting user geolocation based on IP address.
Supports **MaxMind GeoLite2** and **IP2Location**, with optional fallback, mock IP in dev mode, and automatic request listener.

---

⚙️ Installation
---------------

[](#️-installation)

- `composer require ndevs-eu/geo-ip-bundle`
- `Copy example config to /config/packages/geo_ip.yaml`
- `Add env variables to your .env file (GEOIP_MAXMIND_LICENSE_KEY, GEOIP_IP2LOCATION_LICENSE_KEY)`
- `Run bin/console geoip:pull-maxmind-database`
- `Run bin/console geoip:pull-ip2loc-lite-database`

---

📁 Configuration structure (`config/packages/geo_ip.yaml`)
---------------------------------------------------------

[](#-configuration-structure-configpackagesgeo_ipyaml)

```
geo_ip:
    listener_enabled: false # Enables request listener to attach geo data

    resolver:
        primary: maxmind       # or 'ip2location'
        fallback: ip2location  # optional

    maxmind:
        path: '%kernel.project_dir%/var/geoip-maxmind/'
        key: '%env(GEOIP_MAXMIND_LICENSE_KEY)%'

    ip2location:
        path: '%kernel.project_dir%/var/geoip-ip2loc/'
        key: '%env(GEOIP_IP2LOCATION_LICENSE_KEY)%'
```

> In `dev` environment you can add a mock IP for testing:
>
> ```
> when@dev:
>     geo_ip:
>         mock_ip: '185.170.167.18'
> ```

---

🧪 Usage in code
---------------

[](#-usage-in-code)

### ✅ Accessing geo data

[](#-accessing-geo-data)

```
$geoData = $request->attributes->get('geoIp');

if ($geoData) {
    $country = $geoData['country'];
    $city = $geoData['city'];
}
```

> The listener injects `geoIp` attribute into each request when enabled.

---

🌍 Downloading databases
-----------------------

[](#-downloading-databases)

### 📥 MaxMind (GeoLite2 City)

[](#-maxmind-geolite2-city)

1. [Register at maxmind.com](https://www.maxmind.com/en/geolite2/signup)
2. Get your `License Key`
3. Download database manually or run:

```
php bin/console geoip:pull-maxmind-database
```

### 📥 IP2Location (Lite BIN)

[](#-ip2location-lite-bin)

1. [Get free version](https://lite.ip2location.com/)
2. Download manually or run:

```
php bin/console geoip:pull-ip2loc-lite-database
```

> Make sure the path in your config matches the location of extracted files.

---

🧪 Mocking IP in dev
-------------------

[](#-mocking-ip-in-dev)

To test without relying on real headers:

```
when@dev:
    geo_ip:
        mock_ip: '8.8.8.8'
```

---

🧰 Available Console Commands
----------------------------

[](#-available-console-commands)

CommandDescription`geoip:pull-maxmind-database`Downloads the latest MaxMind GeoIP DB`geoip:pull-ip2loc-lite-database`Downloads the latest IP2Location Lite DB---

✅ Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Symfony 6.3+
- Extensions:
    - `ext-json`
    - `ext-mbstring`
    - `ext-zip`
    - `ext-curl`
- Composer
- MaxMind GeoIP2 (City or Country)

---

📌 Features
----------

[](#-features)

✅ Auto-detects IP from headers (X-Forwarded-For, Cloudflare, etc.)
✅ Supports fallback resolver if primary fails
✅ Allows IP mocking in dev mode
✅ Docker/proxy/CDN-friendly
✅ Easy integration via DI

---

🙋 FAQ
-----

[](#-faq)

### What if the IP is not found?

[](#what-if-the-ip-is-not-found)

`geoIp` attribute will contain `null` values. No exception is thrown.

### What if I don’t use IP2Location?

[](#what-if-i-dont-use-ip2location)

Just don't define a fallback resolver in config.

---

📄 License
---------

[](#-license)

MIT

GitAds Sponsored
----------------

[](#gitads-sponsored)

[![Sponsored by GitAds](https://camo.githubusercontent.com/ac3b8f666b90de533c7df0403cfe9e54c58dae28c57921dc2f379c7bca781dad/68747470733a2f2f6769746164732e6465762f76312f61642d73657276653f736f757263653d6e646576732d65752f67656f2d69702d62756e646c6540676974687562)](https://gitads.dev/v1/ad-track?source=ndevs-eu/geo-ip-bundle@github)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance58

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

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 ~0 days

Total

8

Last Release

272d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/44aaa88d54eca574246847badd037f8b9b778cc4b33e263a0f6f80b4e3b350b8?d=identicon)[JosefBanya](/maintainers/JosefBanya)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (5 commits)")

---

Tags

symfonybundlegeolocationIPlocationgeo

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ndevs-eu-geo-ip-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/ndevs-eu-geo-ip-bundle/health.svg)](https://phpackages.com/packages/ndevs-eu-geo-ip-bundle)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[winzou/state-machine-bundle

Bundle for the very lightweight yet powerful PHP state machine

34010.4M15](/packages/winzou-state-machine-bundle)[pentatrion/vite-bundle

Vite integration for your Symfony app

2725.3M13](/packages/pentatrion-vite-bundle)[ipip/db

IPIP.net officially supported IP database ipdb format parsing library

139204.2k6](/packages/ipip-db)[hibit-dev/geodetect

Automatically detect user's geo data based on their IP address

2319.5k](/packages/hibit-dev-geodetect)[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)

PHPackages © 2026

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