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

ActiveYii2-extension

scorpsan/yii2-geoip
===================

An extension that allows you to obtain the visitor's IP address and location information from any IP address. Uses http://sypexgeo.net/ for online and http://www.ip2location.com/ library for offline data retrieval.

v1.3.3(3y ago)02.6kBSD-3-ClausePHP

Since Apr 21Pushed 3y agoCompare

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

READMEChangelog (10)Dependencies (3)Versions (11)Used By (0)

yii2-geoip
==========

[](#yii2-geoip)

An extension that allows you to obtain the visitor's location information from any IP address. Uses  for online and  library for offline data retrieval.

Расширение, позволяющее получать информацию о местоположении посетителя с любого IP-адреса. Использует  для онлайн и  библиотеки для офлайн получения данных.

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

[](#installation)

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

You can set the console

```
$ composer require "scorpsan/yii2-geoip"

```

or add

```
"scorpsan/yii2-geoip": "*"

```

in `require` section in `composer.json` file.

Using
-----

[](#using)

Once the extension is installed, simply use it in your code by :

Add following code to your configuration file of application:

```
...
'components' => [
    ...
    'geoIp' => [
        'class' => 'scorpsan\geoip\GeoIp',
// uncomment next line if you register on sypexgeo.net and paste your key
//        'keySypex' => 'key-sypexgeo-net-this',
// if need more timeout (default 5 = 5000 millisecond)
//        'timeout' => 6,
    ],
    ...
],
...
```

Get information from Ip User: Online

```
var_dump(Yii::$app->geoIp->info);
```

Offline

```
var_dump(Yii::$app->geoIp->infoDb);
```

Get information from Select Ip: Online

```
var_dump(Yii::$app->geoIp->getInfo('255.255.255.255'));
```

Offline

```
var_dump(Yii::$app->geoIp->getInfoDb('255.255.255.255'));
```

Get User Ip:

```
var_dump(Yii::$app->geoIp->ip);
```

Return Data
-----------

[](#return-data)

Online

```
     * Returned information by IP address with following paramters:
     * - `ip`               - Visitor IP address, or IP address specified as parameter.
     * - `city`             - Object City information
     * -- [id] => 625144
     * -- [lat] => 53.9
     * -- [lon] => 27.56667
     * -- [name_ru] => Минск
     * -- [name_en] => Minsk
     * -- [name_de] => Minsk
     * -- [name_fr] => Minsk
     * -- [name_it] => Minsk
     * -- [name_es] => Minsk
     * -- [name_pt] => Minsk
     * -- [okato] => 5000000000
     * -- [vk] => 282
     * -- [population] => 1742124
     * - `region`           - Object Region information
     * -- [id] => 625143
     * -- [lat] => 53.9
     * -- [lon] => 27.57
     * -- [name_ru] => Минск
     * -- [name_en] => Horad Minsk
     * -- [name_de] => Minsk
     * -- [name_fr] => Minsk
     * -- [name_it] => Minsk
     * -- [name_es] => Minsk
     * -- [name_pt] => Minsk
     * -- [iso] => BY-HM
     * -- [timezone] => Europe/Minsk
     * -- [okato] => 5
     * -- [auto] => 7
     * -- [vk] => 0
     * -- [utc] => 3
     * - `country`          - Object Country information
     * -- [id] => 36
     * -- [iso] => BY
     * -- [continent] => EU
     * -- [lat] => 53
     * -- [lon] => 28
     * -- [name_ru] => Беларусь
     * -- [name_en] => Belarus
     * -- [name_de] => Weißrussland
     * -- [name_fr] => Biélorussie
     * -- [name_it] => Bielorussia
     * -- [name_es] => Bielorrusia
     * -- [name_pt] => Bielorrússia
     * -- [timezone] => Europe/Minsk
     * -- [area] => 207600
     * -- [population] => 9685000
     * -- [capital_id] => 625144
     * -- [capital_ru] => Минск
     * -- [capital_en] => Minsk
     * -- [cur_code] => BYR
     * -- [phone] => 375
     * -- [neighbours] => PL,LT,UA,RU,LV
     * -- [vk] => 3
     * -- [utc] => 3
     * - `error`            - Error data.
     * - `request`          - Request code.
     * - `created`          - Date created info in database.
     * - `timestamp`        - Timestamp request.
     *
     * @return array|false
     */
```

Offline

```
     * Returned information by IP address with following paramters:
     * - `ipAddress`       - Visitor IP address, or IP address specified as parameter.
     * - `countryName`     - Name Country in English.
     * - `countryCode`     - Two-letter ISO 3166-1 alpha-2 country code.
     *
     * @return array|false
     */
```

Usage Session for minimize requests to Sypexgeo
-----------------------------------------------

[](#usage-session-for-minimize-requests-to-sypexgeo)

PHP for controller (for examle)

```
/** Get User Location */
        //unset($session['_location']);
        if (isset($session['_location']) && !empty($session['_location']['userCountry'])) {
            $app->params['userCountry'] = $session['_location']['userCountry'];
            $app->params['userCountryCode'] = $session['_location']['userCountryCode'];
            $app->params['userCountryRegion'] = $session['_location']['userCountryRegion'];
            $app->params['userCountryCity'] = $session['_location']['userCountryCity'];
            $app->params['userPhoneCode'] = $session['_location']['userPhoneCode'];
        } else {
            //$geoip = $app->geoip->getInfo('93.176.236.137');
            $geoip = $app->geoip->info;
            if (isset($geoip->ip)) :
                $app->params['userCountry'] = $geoip->country->name_en;
                $app->params['userCountryCode'] = $geoip->country->iso;
                $app->params['userCountryRegion'] = $geoip->region->name_en;
                $app->params['userCountryCity'] = $geoip->city->name_en;
                $app->params['userPhoneCode'] = $geoip->country->phone;
            else :
                $geoip = $app->geoip->infoDb;
                if (isset($geoip['ipAddress'])) :
                    $app->params['userCountry'] = $geoip['countryName'];
                    $app->params['userCountryCode'] = $geoip['countryCode'];
                    $app->params['userCountryRegion'] = $geoip['regionName'];
                    $app->params['userCountryCity'] = $geoip['cityName'];
                    $app->params['userPhoneCode'] = $geoip['iddCode'];
                endif;
            endif;
            $session['_location'] = [
                'userCountry' => $app->params['userCountry'],
                'userCountryCode' => $app->params['userCountryCode'],
                'userCountryRegion' => $app->params['userCountryRegion'],
                'userCountryCity' => $app->params['userCountryCity'],
                'userPhoneCode' => $app->params['userPhoneCode'],
            ];
        }
```

params.php

```
return [
    ...
    'userCountry' => 'World',
    'userCountryCode' => 'wl',
    'userCountryRegion' => '',
    'userCountryCity' => '',
    'userPhoneCode' => '1',
    ...
];
```

License
-------

[](#license)

yii2-geoip is released under the BSD 3-Clause License.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity69

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

Recently: every ~94 days

Total

10

Last Release

1118d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/766d6bd8121dbd307eef958556d62ec72bc9db1a931e4238dc6dd7646a6955e6?d=identicon)[scorpsan](/maintainers/scorpsan)

---

Top Contributors

[![scorpsan](https://avatars.githubusercontent.com/u/32801067?v=4)](https://github.com/scorpsan "scorpsan (38 commits)")

---

Tags

geoipIPyii2extensionlocationgeocountrycityregion

### Embed Badge

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

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

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[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)[nevadskiy/laravel-geonames

Populate your database using the GeoNames service.

2715.1k](/packages/nevadskiy-laravel-geonames)[hibit-dev/geodetect

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

2319.5k](/packages/hibit-dev-geodetect)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1873.8k1](/packages/sjaakp-yii2-spatial)[tigrov/yii2-country

Country data for Yii2 using Intl extension and more.

151.1k](/packages/tigrov-yii2-country)

PHPackages © 2026

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