yii2-ip2location This extension works with IP2Location on Yii2 Framework.

  1. Installation
  2. Quick Start
  3. Usage
  4. Key Notes
  5. Database Update
  6. Resources

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

Installation

  • 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',
        'database' => __DIR__ .DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'IP2Location'.DIRECTORY_SEPARATOR.'IP2LOCATION-LITE-DB1.BIN',
        'mode' => 'FILE_IO',
	],
]

Usage

$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

php_gmp

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).

Resources

0 0
4 followers
724 downloads
Yii Version: 2.0
License: MIT
Category: Web Service
Developed by: Anil Chaudhari
Created on: Aug 4, 2015
Last updated: 8 years ago

Downloads

show all

Related Extensions