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

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

crgao/ip2region
===============

Ip2Region for PHP

v1.0.0(7y ago)014Apache-2.0PHPPHP &gt;=5.3

Since Nov 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/CRGao/ip2region)[ Packagist](https://packagist.org/packages/crgao/ip2region)[ RSS](/packages/crgao-ip2region/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

ip2region - 最自由的ip地址查詢庫，ip到地區的映射庫，提供Binary,B樹和純內存三種查詢算法，媽媽再也不用擔心我的ip地址定位。

\##將該庫打包成 PHP composer 版本

### 1. 99.9%準確率，定時更新：

[](#1-999準確率定時更新)

數據聚合了一些知名ip到地名查詢提供商的數據，這些是他們官方的的準確率，經測試著實比純真啥的準確多了。
每次聚合一下數據需要1-2天，會不定時更新。

### 2. 標準化的數據格式：

[](#2-標準化的數據格式)

每條ip數據段都固定了格式：*城市Id|國家|區域|省份|城市|ISP*

只有中國的數據精確到了城市，其他國家只能定位到國家，後前的選項全部是0，已經包含了全部你能查到的大大小小的國家。 （請忽略前面的城市Id，個人項目需求）

### 3. 體積小：

[](#3-體積小)

生成的數據庫文件ip2region.db只有1.5M（1.2版本前是3.5M）

### 4. composer 安裝：

[](#4-composer-安裝)

```
composer require crgao/ip2region
```

```
$ip2region = new Ip2Region();

$ip = '101.96.11.3';

#可拿來驗證IP格式
$ip = Ip2Region::safeIp2long($ip);

#btreeSearch
$info = $ip2region->btreeSearch($ip);
print_r($info);

#binarySearch
$info = $ip2region->binarySearch($ip);
print_r($info);

#memorySearch
$info = $ip2region->memorySearch($ip);
print_r($info);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

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

Unknown

Total

1

Last Release

2740d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4899233ce7730e8d6d8d7f04e654e7e2a6ce133cfd544f0bd462136743b3f693?d=identicon)[CRGao](/maintainers/CRGao)

---

Top Contributors

[![CRGao](https://avatars.githubusercontent.com/u/8327466?v=4)](https://github.com/CRGao "CRGao (1 commits)")

---

Tags

Ip2Region

### Embed Badge

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

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

###  Alternatives

[jjgrainger/posttypes

Simple WordPress custom post types.

382568.8k12](/packages/jjgrainger-posttypes)[league/glide-laravel

Glide adapter for Laravel

1433.2M35](/packages/league-glide-laravel)[nacmartin/phpexecjs

Run JavaScript code from PHP

1511.3M4](/packages/nacmartin-phpexecjs)[chriskonnertz/open-graph

Class that assists in building Open Graph meta tags

117428.6k3](/packages/chriskonnertz-open-graph)[jeremykenedy/slack-laravel

Laravel integration for the jeremykenedy/slack package, including facades and service providers.

54738.8k](/packages/jeremykenedy-slack-laravel)

PHPackages © 2026

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