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).
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.