Yii 2.0: yii2-ip2location-extension

This extension use IP2Location BIN database to lookup visitor geographical location by their IP address.
4 followers

Requirements

Yii 2

Installation

php composer.phar require ip2location/ip2location-php:8.*

Usage

/*
    Default file I/O lookup
*/
$db = new \IP2Location\Database('path_to/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::FILE_IO);
 
$records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL);
 
echo 'IP Number             : ' . $records['ipNumber'] . "\n";
echo 'IP Version            : ' . $records['ipVersion'] . "\n";
echo 'IP Address            : ' . $records['ipAddress'] . "\n";
echo 'Country Code          : ' . $records['countryCode'] . "\n";
echo 'Country Name          : ' . $records['countryName'] . "\n";
echo 'Region Name           : ' . $records['regionName'] . "\n";
echo 'City Name             : ' . $records['cityName'] . "\n";
echo 'Latitude              : ' . $records['latitude'] . "\n";
echo 'Longitude             : ' . $records['longitude'] . "\n";
echo 'Area Code             : ' . $records['areaCode'] . "\n";
echo 'IDD Code              : ' . $records['iddCode'] . "\n";
echo 'Weather Station Code  : ' . $records['weatherStationCode'] . "\n";
echo 'Weather Station Name  : ' . $records['weatherStationName'] . "\n";
echo 'MCC                   : ' . $records['mcc'] . "\n";
echo 'MNC                   : ' . $records['mnc'] . "\n";
echo 'Mobile Carrier        : ' . $records['mobileCarrierName'] . "\n";
echo 'Usage Type            : ' . $records['usageType'] . "\n";
echo 'Elevation             : ' . $records['elevation'] . "\n";
echo 'Net Speed             : ' . $records['netSpeed'] . "\n";
echo 'Time Zone             : ' . $records['timeZone'] . "\n";
echo 'ZIP Code              : ' . $records['zipCode'] . "\n";
echo 'Domain Name           : ' . $records['domainName'] . "\n";
echo 'ISP Name              : ' . $records['isp'] . "\n";

Resources

Total 1 comment

#20047 report it
robregonm at 2017/03/14 03:42pm
Nice alternative

I use to use Ip2Location directl from nginx, but this is a good alternative for a PHP-only solutions

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet