Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

IP2Location Laravel 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.
https://github.com/ip2location/ip2location-laravel

geolocation ip-address-database ip-database ip-geolocation ip-lookup ip2location ip2location-laravel laravel

Last synced: 8 days ago
JSON representation

IP2Location Laravel 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.

Awesome Lists containing this project

README

        

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

IP2Location Laravel extension 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, 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.

*Note: This extension works in Laravel 6, Laravel 7, Laravel 8, Laravel 9, Laravel 10 and Laravel 11.*

## INSTALLATION

Run the command: `composer require ip2location/ip2location-laravel` to download the package into the Laravel platform.

## USAGE

IP2Location Laravel extension is able to query the IP address information from either BIN database or web service. This section will explain how to use this extension to query from BIN database and web service.

### BIN DATABASE

1. Download IP2Location BIN database
- IP2Location free LITE database at https://lite.ip2location.com
- IP2Location commercial database at https://www.ip2location.com
2. To use IP2Location databases, create a folder named as `ip2location` in the `database` directory.
3. Unzip and copy the BIN file into `database/ip2location/` folder.
4. Rename the BIN file to IP2LOCATION.BIN.
5. Create a **TestController** in Laravel using the below command line
```
php artisan make:controller TestController
```
6. Open the **app/Http/Controllers/TestController.php** in any text editor.
7. To use IP2Location databases, add the below lines into the controller file.
```php
";
echo 'IP Version : ' . $records['ipVersion'] . "
";
echo 'IP Address : ' . $records['ipAddress'] . "
";
echo 'Country Code : ' . $records['countryCode'] . "
";
echo 'Country Name : ' . $records['countryName'] . "
";
echo 'Region Name : ' . $records['regionName'] . "
";
echo 'City Name : ' . $records['cityName'] . "
";
echo 'Latitude : ' . $records['latitude'] . "
";
echo 'Longitude : ' . $records['longitude'] . "
";
echo 'Area Code : ' . $records['areaCode'] . "
";
echo 'IDD Code : ' . $records['iddCode'] . "
";
echo 'Weather Station Code : ' . $records['weatherStationCode'] . "
";
echo 'Weather Station Name : ' . $records['weatherStationName'] . "
";
echo 'MCC : ' . $records['mcc'] . "
";
echo 'MNC : ' . $records['mnc'] . "
";
echo 'Mobile Carrier : ' . $records['mobileCarrierName'] . "
";
echo 'Usage Type : ' . $records['usageType'] . "
";
echo 'Elevation : ' . $records['elevation'] . "
";
echo 'Net Speed : ' . $records['netSpeed'] . "
";
echo 'Time Zone : ' . $records['timeZone'] . "
";
echo 'ZIP Code : ' . $records['zipCode'] . "
";
echo 'Domain Name : ' . $records['domainName'] . "
";
echo 'ISP Name : ' . $records['isp'] . "
";
echo 'Address Type : ' . $records['addressType'] . "
";
echo 'Category : ' . $records['category'] . "
";
echo 'District : ' . $records['district'] . "
";
echo 'ASN : ' . $records['asn'] . "
";
echo 'AS : ' . $records['as'] . "
";
}
}
```
8. Add the following line into the *routes/web.php* file.
```
Route::get('test', 'App\Http\Controllers\TestController@lookup');
```
9. Enter the URL /test and run. You should see the information of **8.8.8.8** IP address.

### WEB SERVICE

1. To use IP2Location.io or IP2Location web service, create a new file called "site_vars.php" in `config` directory.
2. In the site_vars.php, save the following contents for IP2Location.io:
```
'your_api_key', // Required. Your IP2Location.io API key.
'IP2LocationioLanguage' => 'en', // Optional. Refer to https://www.ip2location.io/ip2location-documentation for available languages.
];
```
Or save the following contents for IP2Location:
```php
'your_api_key', // Required. Your IP2Location API key.
'IP2LocationPackage' => 'WS1', // Required. Choose the package you would like to use.
'IP2LocationUsessl' => false, // Optional. Use https or http.
'IP2LocationAddons' => [], // Optional. Refer to https://www.ip2location.com/web-service/ip2location for the list of available addons.
'IP2LocationLanguage' => 'en', // Optional. Refer to https://www.ip2location.com/web-service/ip2location for available languages.
];
```
3. Create a **TestController** in Laravel using the below command line
```
php artisan make:controller TestController
```
4. Open the **app/Http/Controllers/TestController.php** in any text editor.
5. To use IP2Location databases, add the below lines into the controller file.
```php
';
print_r($records);
echo '';
}
}

```
6. Add the following line into the *routes/web.php* file.
```
Route::get('test', 'App\Http\Controllers\TestController@lookup');
```
7. Enter the URL /test and run. You should see the information of **8.8.8.8** IP address.

### IPTOOLS

1. Create a **TestController** in Laravel using the below command line
```
php artisan make:controller TestController
```
2. Open the **app/Http/Controllers/TestController.php** in any text editor.
3. To use IP2Location IPTools class, add the below lines into the controller file.
```php
';
var_dump(IP2LocationLaravel::isIpv6('2001:4860:4860::8888'));echo '
';
print_r(IP2LocationLaravel::ipv4ToDecimal('8.8.8.8'));echo '
';
print_r(IP2LocationLaravel::decimalToIpv4(134744072));echo '
';
print_r(IP2LocationLaravel::ipv6ToDecimal('2001:4860:4860::8888'));echo '
';
print_r(IP2LocationLaravel::decimalToIpv6('42541956123769884636017138956568135816'));echo '
';
print_r(IP2LocationLaravel::ipv4ToCidr('8.0.0.0', '8.255.255.255'));echo '
';
print_r(IP2LocationLaravel::cidrToIpv4('8.0.0.0/8'));echo '
';
print_r(IP2LocationLaravel::ipv6ToCidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff'));echo '
';
print_r(IP2LocationLaravel::cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64'));echo '
';
print_r(IP2LocationLaravel::compressIpv6('2002:0000:0000:1234:FFFF:FFFF:FFFF:FFFF'));echo '
';
print_r(IP2LocationLaravel::expandIpv6('2002::1234:FFFF:FFFF:FFFF:FFFF'));echo '
';
}
}

```
4. Add the following line into the *routes/web.php* file.
```
Route::get('test', 'App\Http\Controllers\TestController@lookup');
```
5. Enter the URL /test and run.

## DEPENDENCIES

This library requires either 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

For IP2Location API key, you can sign up [IP2Location Web Service](https://www.ip2location.com/web-service/ip2location) 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