PHPackages                             ip2location/ip2location-codeigniter4 - 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. [API Development](/categories/api)
4. /
5. ip2location/ip2location-codeigniter4

ActiveLibrary[API Development](/categories/api)

ip2location/ip2location-codeigniter4
====================================

IP2Location library for CodeIgniter 4. Use IP2Location geolocation database to lookup the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, IP address type and IAB advertising category from IP address using IP2Location database.

1.1.1(2y ago)4141MITPHP

Since Sep 2Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/ip2location/ip2location-codeigniter4)[ Packagist](https://packagist.org/packages/ip2location/ip2location-codeigniter4)[ Docs](https://www.ip2location.com)[ RSS](/packages/ip2location-ip2location-codeigniter4/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

IP2Location CodeIgniter 4 Library
=================================

[](#ip2location-codeigniter-4-library)

This module enables users to retrieve below geolocation information from an IP address. It supports both the IPv4 and IPv6 address.

- Country
- Region
- City
- Latitude &amp; Longitude
- ZIP Code
- Time Zone
- Area Code
- Net Speed
- ISP
- Domain
- Mobile Information
- Weather Station Information
- Elevation
- Usage Type
- Address Type
- Category

This library will only work with CodeIgniter 4. For CodeIgniter 3, you can get it from [here](https://github.com/ip2location/codeigniter-ip2location).

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

[](#installation)

Upload `Controllers`, `Libraries` and `Models` to CodeIgniter `app` folder.

Usage
-----

[](#usage)

This module is able to query the IP address information from either BIN database or web service. This section will explain how to use this extension to query from BIN database and web service.

Sample codes are given in this project, under **Controllers** folder. After added the following line into the *app\\Config\\Routes.php* file, you may run the sample code by using &lt;your\_domain&gt;/index.php/ip2location\_test.

```
$routes->get('ip2location_test', 'IP2Location_test::index');
```

### BIN Database

[](#bin-database)

Use following codes in your application for get geolocation information.

```
    // (optional) Define IP2Location database path. By default, the IP2LOCATION_DATABASE is pointed to *app/Libraries/IP2Location/IP2LOCATION-DB.BIN* if you choose not to change the original settings.
    define('IP2LOCATION_DATABASE', '/path/to/ip2location/database');

    $ipl = new IP2Location_lib();
    $countryCode = $ipl->getCountryCode('8.8.8.8');
```

Below are the methods supported for BIN data file lookup.

```
    $countryCode = $ipl->getCountryCode($ip);
    $countryName = $ipl->getCountryName($ip);
    $regionName = $ipl->getRegionName($ip);
    $cityName = $ipl->getCityName($ip);
    $latitude = $ipl->getLatitude($ip);
    $longitude = $ipl->getLongitude($ip);
    $isp = $ipl->getISP($ip);
    $domainName = $ipl->getDomainName($ip);
    $zipCode = $ipl->getZIPCode($ip);
    $timeZone = $ipl->getTimeZone($ip);
    $netSpeed = $ipl->getNetSpeed($ip);
    $iddCode = $ipl->getIDDCode($ip);
    $areaCode = $ipl->getAreaCode($ip);
    $weatherStationCode = $ipl->getWeatherStationCode($ip);
    $weatherStationName = $ipl->getWeatherStationName($ip);
    $mcc = $ipl->getMCC($ip);
    $mnc = $ipl->getMNC($ip);
    $mobileCarrierName = $ipl->getMobileCarrierName($ip);
    $elevation = $ipl->getElevation($ip);
    $usageType = $ipl->getUsageType($ip);
    $addressType = $ipl->getAddressType($ip);
    $category = $ipl->getCategory($ip);
```

### Web Service

[](#web-service)

Use following codes in your application for get geolocation information.

```
    // (required) Define IP2Location API key.
    define('IP2LOCATION_API_KEY', 'your_api_key');

    // (required) Define IP2Location Web service package of different granularity of return information.
    define('IP2LOCATION_PACKAGE', 'WS1');

    // (optional) Define to use https or http.
    define('IP2LOCATION_USESSL', false);

    // (optional) Define extra information in addition to the above-selected package. Refer to https://www.ip2location.com/web-service/ip2location for the list of available addons.
    define('IP2LOCATION_ADDONS', []);

    // (optional) Define Translation information. Refer to https://www.ip2location.com/web-service/ip2location for available languages.
    define('IP2LOCATION_LANGUAGE', 'zh-cn');

    $ipl = new IP2Location_lib();
    print_r ($ipl->getWebService('8.8.8.8'));
```

To use IP2Location.io API for getting the geolocation information, you can use the following code to do so:

```
	// (required) Define IP2Location.io API key.
    define('IP2LOCATION_IO_API_KEY', 'your_api_key');

    // (optional) Define Translation information. Refer to https://www.ip2location.io/ip2location-documentation for available languages.
    define('IP2LOCATION_IO_LANGUAGE', 'zh-cn');

    $ipl = new IP2Location_lib();
    print_r ($ipl->getWebService('8.8.8.8'));
```

### MySQL Query

[](#mysql-query)

Use following codes in your application for get geolocation information.

```
    define('IP2LOCATION_DATABASE_TABLE', 'ip2location_table_name');

    $db = model('IP2Location_model', false);
    print_r ($db->lookup('8.8.8.8'));
```

### IPTools

[](#iptools)

Use following codes in your application for get IPTools class information.

```
    $ipl = new IP2Location_lib();
    var_dump($ipl->isIpv4('8.8.8.8'));echo '';
    var_dump($ipl->isIpv6('2001:4860:4860::8888'));echo '';
    print_r($ipl->ipv4ToDecimal('8.8.8.8'));echo '';
    print_r($ipl->decimalToIpv4(134744072));echo '';
    print_r($ipl->ipv6ToDecimal('2001:4860:4860::8888'));echo '';
    print_r($ipl->decimalToIpv6('42541956123769884636017138956568135816'));echo '';
    print_r($ipl->ipv4ToCidr('8.0.0.0', '8.255.255.255'));echo '';
    print_r($ipl->cidrToIpv4('8.0.0.0/8'));echo '';
    print_r($ipl->ipv6ToCidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff'));echo '';
    print_r($ipl->cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64'));echo '';
    print_r($ipl->compressIpv6('2002:0000:0000:1234:FFFF:FFFF:FFFF:FFFF'));echo '';
    print_r($ipl->expandIpv6('2002::1234:FFFF:FFFF:FFFF:FFFF'));echo '';
```

Dependencies
------------

[](#dependencies)

This module requires IP2Location BIN data file or IP2Location API key to function. You may download the BIN data file at

- IP2Location LITE BIN Data (Free):
- IP2Location Commercial BIN Data (Comprehensive):

An outdated BIN database was provided in this release for your testing. You are recommended to visit the above links to download the latest BIN database.

For the BIN database update, you can just rename the downloaded BIN database to *IP2LOCATION-DB.BIN* and replace the copy in *app/Libraries/IP2Location/* (if you didn't change the default IP2LOCATION\_DATABASE constant as described in the Usage section).

You can also sign up for [IP2Location Web Service](https://www.ip2location.com/web-service/ip2location) or [IP2Location.io IP GEOLOCATION API](https://www.ip2location.io/sign-up) to get one free API key.

IPv4 BIN vs IPv6 BIN
--------------------

[](#ipv4-bin-vs-ipv6-bin)

- Use the IPv4 BIN file if you just need to query IPv4 addresses.
- Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

SUPPORT
-------

[](#support)

Email:

Website:

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance47

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Total

3

Last Release

948d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5fbe791b4a8d666a158043146d73380f05a0bea9062f0fa0852bf82f6bc762c?d=identicon)[ip2location](/maintainers/ip2location)

---

Top Contributors

[![ip2location-com](https://avatars.githubusercontent.com/u/6367210?v=4)](https://github.com/ip2location-com "ip2location-com (8 commits)")

---

Tags

codeigniter4geolocationip-databaseip-geolocationip-lookupip2locationgeolocationip geolocationip-lookupip-databaseip2location-bin-databasegeolocation-informationcodeigniter-ip2locationip-address-database

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ip2location-ip2location-codeigniter4/health.svg)

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

###  Alternatives

[geoip2/geoip2

MaxMind GeoIP PHP API

2.5k92.0M358](/packages/geoip2-geoip2)[ipgeolocation/ipgeolocation-php-sdk

Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.

414.8k](/packages/ipgeolocation-ipgeolocation-php-sdk)[igaster/laravel_cities

Seed all countries/cities from geonames.org database. Searchable DB tree, ready to use API &amp; a bonus vue.js component!

18394.5k1](/packages/igaster-laravel-cities)[jeroendesloovere/geolocation-php-api

This Geolocation PHP class connects to Google Maps API to find latitude/longitude or address.

79325.4k4](/packages/jeroendesloovere-geolocation-php-api)[maxh/php-nominatim

Wrapper for Nominatim API

51411.1k2](/packages/maxh-php-nominatim)[jbohme/nominatim-laravel

Wrapper for Nominatim API to Laravel

1240.5k](/packages/jbohme-nominatim-laravel)

PHPackages © 2026

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