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

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

gupalo/geoip
============

GeoIP client

1.3.3(1y ago)015.3k↓31.5%1MITPHPPHP ^8.0CI failing

Since Jan 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/gupalo/geoip)[ Packagist](https://packagist.org/packages/gupalo/geoip)[ RSS](/packages/gupalo-geoip/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (15)Used By (0)

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

[](#geoip-client)

Adapter for MaxMind and Sypex GeoIP database clients.

Usage
-----

[](#usage)

```
composer require gupalo/geoip

```

Put GeoIP databases to some directory. Supported databases:

- GeoIP2-City.mmdb or GeoLite2-City.mmdb
- GeoIP2-Country.mmdb or GeoLite2-Country.mmdb
- GeoIP2-Domain.mmdb
- GeoIP2-ISP.mmdb
- SxGeoMax.dat

You can download MaxMind lite databases:

```
export MAX_MIND_LICENSE_KEY="XXXXXXXXXXXXXXXX" # you need to register to get the key
export TARGET_DIR="/opt/geoip" # or any other folder where you keep geoip files
curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz&license_key=${MAX_MIND_LICENSE_KEY}" | tar zxf - -C ${TARGET_DIR}/ --strip-components=1 --no-anchored --wildcards *.mmdb
curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz&license_key=${MAX_MIND_LICENSE_KEY}" | tar zxf - -C ${TARGET_DIR}/ --strip-components=1 --no-anchored --wildcards *.mmdb

```

Usage:

```
$parser = new GeoIpParser($dir);
$geoIp = $parser->parse('1.1.1.1');

$ip = $geoip->getIp();
$isValidIp = $geoip->isValidIp();
$city = $geoip->getCity();
$countryCode = $geoip->getCountryCode();
$country = $geoip->getCountry();
$continentCode = $geoip->getContinentCode();
$postalCode = $geoip->getPostalCode();
$domain = $geoip->getDomain();
$asnNumber = $geoip->getAsnNumber();
$asnOrganization = $geoip->getAsnOrganization();
$isp = $geoip->getIsp();
$organization = $geoip->getOrganization();
$latitude = $geoip->getLatitude();
$longitude = $geoip->getLongitude();
$region = $geoip->getRegion();
$timezone = $geoip->getTimezone();
$currencyCode = $geoip->getCurrencyCode();
$cityPopulation = $geoip->getCityPopulation();
$cityTel = $geoip->getCityTel();
$regionAuto = $geoip->getRegionAuto();
$countryArea = $geoip->getCountryArea();
$countryPopulation = $geoip->getCountryPopulation();
$countryCapital = $geoip->getCountryCapital();
$countryPhoneCode = $geoip->getCountryPhoneCode();

```

Advanced Usage
--------------

[](#advanced-usage)

If data may exist in several databases like latitude/longitude then data is taken from the best database:

- MaxMind City (if not available - MaxMind City Lite)
- Sypex (if has city data)
- MaxMind Country (if not available - MaxMind Country Lite)
- Sypex

You can get data from specific database:

```
$parser = new GeoIpParser($dir);
$geoIp = $parser->parseAdvanced('1.1.1.1');
$latitudes = [
    $geoIp->getSypexCityLatitude(),
    $geoIp->getSypexRegionLatitude(),
    $geoIp->getSypexCountryLatitude(),
    $geoIp->getMaxMindCityLatitude(),
];

```

Also you can get raw data from:

```
$parser = new GeoIpParser($dir);
$geoIp = $parser->parseAdvanced('1.1.1.1');
$raw = [
    $geoIp->getSypexCityRaw(),
    $geoIp->getMaxMindCountryRaw(),
    $geoIp->getMaxMindCityRaw(),
    $geoIp->getMaxMindDomainRaw(),
    $geoIp->getMaxMindIspRaw(),
];

```

Symfony
-------

[](#symfony)

Add to `config/services.yaml`

```
parameters:
    ...
    env(GEOIP_DIR): '%kernel.project_dir%/data/geoip'

services:
    ...
    Gupalo\GeoIp\GeoIpParser:
        arguments: ['%env(resolve:GEOIP_DIR)%']
    Gupalo\GeoIp\Twig\GeoIpExtension:
        tags: ['twig.extension']

```

Use with autowire

```
/**
 * @Route("/test", name="test")
 */
public function test(GeoIpParser $geoIpParser): Response
{
    dd($geoIpParser->parse('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_country`: convert IP to country name - `'1.1.1.1'|ip_country` - Australia, Russia, ...
- `ip_flag`: convert IP to HTML with flag - `'1.1.1.1'|ip_flag`
- `country_code_flag`: convert country code to HTML with flag - `'RU'|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

40

—

FairBetter than 86% of packages

Maintenance40

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

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

Recently: every ~372 days

Total

14

Last Release

505d ago

PHP version history (4 changes)1.0.0PHP &gt;=7.3

1.1.4PHP &gt;=7.4

1.2.0PHP ^8.0

1.3.0PHP ^8.1

### 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 (10 commits)")

---

Tags

geoipgeoip-clientgeoip-databasesmaxmindmaxmind-citymaxmind-countrymmdbsypex

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[moodle/moodle

Moodle - the world's open source learning platform

7.2k88.5k88](/packages/moodle-moodle)[aknife/ip

获取ip信息，支持ipv4和 ipv6

263.4k1](/packages/aknife-ip)

PHPackages © 2026

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