An open API service indexing awesome lists of open source software.

https://github.com/ip2location/ip2location-cakephp

IP2Location CakePHP plugin 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.
https://github.com/ip2location/ip2location-cakephp

cakephp geolocation ip-address-database ip-database ip-geolocation ip-lookup ip2location ip2location-bin-databases ip2location-cakephp

Last synced: 18 days ago
JSON representation

IP2Location CakePHP plugin 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.

Awesome Lists containing this project

README

        

# IP2Location CakePHP Plugin
[![Latest Stable Version](https://img.shields.io/packagist/v/ip2location/ip2location-cakephp.svg)](https://packagist.org/packages/ip2location/ip2location-cakephp)
[![Total Downloads](https://img.shields.io/packagist/dt/ip2location/ip2location-cakephp.svg?style=flat-square)](https://packagist.org/packages/ip2location/ip2location-cakephp)

IP2Location CakePHP plugin enables the user to find the country, region, district, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type, IP address type, IAB advertising category and ASN 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 CakePHP.

Note: This plugin works in CakePHP 4 and CakePHP 5.

## INSTALLATION
1. Run the command: `composer require ip2location/ip2location-cakephp` to download the plugin into the CakePHP platform.
2. Download latest IP2Location BIN database
- IP2Location free LITE database at https://lite.ip2location.com
- IP2Location commercial database at https://www.ip2location.com
3. Unzip and copy the BIN file into */vendor/ip2location/ip2location-cakephp/src/Data* folder.
4. Rename the BIN file to IP2LOCATION.BIN.

**Note:** The plugin has included an old BIN database for your testing and development purpose.
You may want to download a latest copy of BIN database as the URL stated above.
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
In this tutorial, we will show you on how to create a **TestsController** to display the IP information.

1. Create a **TestsController** in CakePHP using the below command line
```
php bin/cake bake controller Tests
```
2. Create a **Tests** folder in */cakephp/templates* if not exists.
3. Create an empty **index.php** file in */cakephp/templates/Tests* folder.
4. Open the **cakephp/src/Controller/TestsController.php** in any text editor.
5. Remove the contents in TestsController.php and add the below lines into the controller file.

Note: You just need to load the IP2Location library with **use IP2LocationCakePHP\Controller\IP2LocationCoresController** to use the functions.
```
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'] . '
';
echo 'District: ' . $record['district'] . '
';
echo 'ASN: ' . $record['asn'] . '
';
echo 'AS: ' . $record['as'] . '
';

$record = $IP2Location->getWebService('8.8.8.8');
echo 'Result from Web service:
';
echo '

';

print_r ($record);
echo '
';

var_dump($IP2Location->isIpv4('8.8.8.8'));echo '
';
var_dump($IP2Location->isIpv6('2001:4860:4860::8888'));echo '
';
print_r($IP2Location->ipv4ToDecimal('8.8.8.8'));echo '
';
print_r($IP2Location->decimalToIpv4(134744072));echo '
';
print_r($IP2Location->ipv6ToDecimal('2001:4860:4860::8888'));echo '
';
print_r($IP2Location->decimalToIpv6('42541956123769884636017138956568135816'));echo '
';
print_r($IP2Location->ipv4ToCidr('8.0.0.0', '8.255.255.255'));echo '
';
print_r($IP2Location->cidrToIpv4('8.0.0.0/8'));echo '
';
print_r($IP2Location->ipv6ToCidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff'));echo '
';
print_r($IP2Location->cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64'));echo '
';
print_r($IP2Location->compressIpv6('2002:0000:0000:1234:FFFF:FFFF:FFFF:FFFF'));echo '
';
print_r($IP2Location->expandIpv6('2002::1234:FFFF:FFFF:FFFF:FFFF'));echo '
';
}

}
```
5. Enter the URL /Tests and run. You should see the information of **8.8.8.8** IP address.

## 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.io IP Geolocation API](https://www.ip2location.io/sign-up) to get one free API key.

## IPv4 BIN vs IPv6 BIN
Use the IPv4 BIN file if you just need to query IPv4 addresses.

Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

## SUPPORT
Email: [email protected]

Website: https://www.ip2location.com