IP2Location Yii extension
IP2Location Yii extension enables the user to find 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. It has been optimized for speed and memory utilization. Developers can use the API to query all IP2Location BIN databases or web service for applications written using Yii.
INSTALLATION
For Yii2
- Run the command:
php composer.phar require ip2location/ip2location-yii
to download the extension into the Yii2 framework. - Download latest IP2Location BIN database
- IP2Location free LITE database at https://lite.ip2location.com
- IP2Location commercial database at https://www.ip2location.com
- Unzip and copy the BIN file into the Yii2 framework.
Note: The BIN database refers to the binary file ended with .BIN extension, but not the CSV format. Please select the right package for download.
USAGE
use IP2LocationYii\IP2Location_Yii;
// (required) Define IP2Location database path.
define('IP2LOCATION_DATABASE', '/path/to/ip2location/database');
// (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', 'en');
$IP2Location = new IP2Location_Yii();
$record = $IP2Location->get('8.8.8.8');
echo 'Result from BIN Database:
';
echo 'IP Address: ' . $record['ipAddress'] . '
';
echo 'IP Number: ' . $record['ipNumber'] . '
';
echo 'ISO Country Code: ' . $record['countryCode'] . '
';
echo 'Country Name: ' . $record['countryName'] . '
';
echo 'Region Name: ' . $record['regionName'] . '
';
echo 'City Name: ' . $record['cityName'] . '
';
echo 'Latitude: ' . $record['latitude'] . '
';
echo 'Longitude: ' . $record['longitude'] . '
';
echo 'ZIP Code: ' . $record['zipCode'] . '
';
echo 'Time Zone: ' . $record['timeZone'] . '
';
echo 'ISP Name: ' . $record['isp'] . '
';
echo 'Domain Name: ' . $record['domainName'] . '
';
echo 'Net Speed: ' . $record['netSpeed'] . '
';
echo 'IDD Code: ' . $record['iddCode'] . '
';
echo 'Area Code: ' . $record['areaCode'] . '
';
echo 'Weather Station Code: ' . $record['weatherStationCode'] . '
';
echo 'Weather Station Name: ' . $record['weatherStationName'] . '
';
echo 'MCC: ' . $record['mcc'] . '
';
echo 'MNC: ' . $record['mnc'] . '
';
echo 'Mobile Carrier Name: ' . $record['mobileCarrierName'] . '
';
echo 'Elevation: ' . $record['elevation'] . '
';
echo 'Usage Type: ' . $record['usageType'] . '
';
echo 'Address Type: ' . $record['addressType'] . '
';
echo 'Category: ' . $record['category'] . '
';
$record = $IP2Location->getWebService('8.8.8.8');
echo 'Result from Web service:
';
echo '';
print_r ($record);
echo '
';
DEPENDENCIES
This library requires IP2Location BIN data file or IP2Location API key to function. You may download the BIN data file at
- IP2Location LITE BIN Data (Free): https://lite.ip2location.com
- IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com
You can also sign up for IP2Location Web Service to get one free API key.
SUPPORT
Email: [email protected]
Website: https://www.ip2location.com