PHPackages                             xiaogouxo/yii2-ip2region - 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. xiaogouxo/yii2-ip2region

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

xiaogouxo/yii2-ip2region
========================

ip2region extension for yii2 to retrieve Chinese geolocation information

14.8k2PHP

Since Aug 11Pushed 9y agoCompare

[ Source](https://github.com/falcolee/yii2-ip2region)[ Packagist](https://packagist.org/packages/xiaogouxo/yii2-ip2region)[ RSS](/packages/xiaogouxo-yii2-ip2region/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-ip2region
==============

[](#yii2-ip2region)

ip2region extension for yii2

Help you to retrieve Chinese geolocation information in 0.0x ms

\*This extenestion provides two search modes, SEARCH\_BTREE(the default mode) and SEARCH\_BINARY. \*It contains a very small database file,only 3.5M

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

[](#installation)

To install, either run

```
$ php composer.phar require xiaogouxo/yii2-ip2region "*"

```

or add

```
"xiaogouxo/yii2-ip2region": "*"

```

to the `require` section of your `composer.json` file.

============

- Add following lines into `main.php` configuration file:

    ```
      'components' => array(
      	...
          'ip2region' => [
              'class' => '\xiaogouxo\ip2region\Geolocation',
              'mode' => 'SEARCH_BTREE',
          ]
      	...
      ),

    ```

Usage
=====

[](#usage)

$ip = Yii::$app-&gt;request-&gt;userIP; $region = Yii::$app-&gt;ip2region-&gt;getRegion($ip);

Returns the following information
=================================

[](#returns-the-following-information)

|中国|华南|广东省|深圳市|鹏博士

More
====

[](#more)

Inspired by yii2-IP2Location and ip2region.

中文说明
====

[](#中文说明)

准确率99.9%的ip到地名的映射库，0.0x毫秒级查询，数据库文件大小只有3.5M 提供SEARCH\_BTREE(默认)和SEARCH\_BINARY两种查询模式

安装
==

[](#安装)

- 在 `main.php` 添加如下信息:

    ```
      'components' => array(
      	...
          'ip2region' => [
              'class' => '\xiaogouxo\ip2region\Geolocation',
              'database' => dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'xiaogouxo'.DIRECTORY_SEPARATOR.'yii2-ip2region'.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'ip2region.db',
              'mode' => 'SEARCH_BTREE',
          ]
      	...
      ),

    ```

感谢
==

[](#感谢)

狮子的魂提供的ipregion 和yii2-IP2Location插件

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fbbc85f969923e58bd033c9ec59e20eba3258ac5fdc6bdb8f3b6f098ffc2e8e?d=identicon)[xiaogouxo](/maintainers/xiaogouxo)

---

Top Contributors

[![falcolee](https://avatars.githubusercontent.com/u/4252835?v=4)](https://github.com/falcolee "falcolee (3 commits)")

### Embed Badge

![Health badge](/badges/xiaogouxo-yii2-ip2region/health.svg)

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

###  Alternatives

[abeautifulsite/jquery-minicolors

jQuery MiniColors Plugin

95478.4k1](/packages/abeautifulsite-jquery-minicolors)[opensoft/epl

The library is a php wrapper for the EPL2 Programming Language. At present do not support all commands EPL2.

1019.5k1](/packages/opensoft-epl)

PHPackages © 2026

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