Yii 2.0: yii2-ip2location

This extension works with IP2Location on Yii2 Framework.

This extension provides country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection speed, IDD code, area code, weather station code, weather station name, MNC, MCC, mobile brand, elevation, and usage type from IP address by using IP2Location database. This module uses a file based database available at IP2Location.com


  • Download
  • Extract this package to frontend/components

Composer installation is coming soon.

Quick Start

Use the following methods to retrieve geolocation information. * Add following lines into main.php configuration file:

'components' => [
     'ip2location' => [
        'class' => '\frontend\components\IP2Location\Geolocation',
        'mode' => 'FILE_IO',


$ip = Yii::$app->request->userIP
$countryCode = Yii::$app->ip2location->getCountryCode($ip);
$countryName = Yii::$app->ip2location->getCountryName($ip);
$regionName = Yii::$app->ip2location->getRegionName($ip);
$cityName = Yii::$app->ip2location->getCityName($ip);
$latitude = Yii::$app->ip2location->getLatitude($ip);
$longitude = Yii::$app->ip2location->getLongitude($ip);
.... And so on

Key Notes

You must enable


extension before using it.

Database Update

IP2Location database is updated monthly. You can get the latest database from http://www.ip2location.com (Commercial version) or http://lite.ip2location.com (Free version).


Be the first person to leave a comment

Please to leave your comment.

Create extension