PHP code example of ip2location / ip2location-laravel
1. Go to this page and download the library: Download ip2location/ip2location-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ip2location / ip2location-laravel example snippets
return [
'IP2LocationAPIKey' => '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.
];
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use IP2LocationLaravel; //use IP2LocationLaravel class
class TestController extends Controller
{
//Create a lookup function for display
public function lookup(){
//Try query the geolocation information of 8.8.8.8 IP address
$records = IP2LocationLaravel::get('8.8.8.8', 'ws');
echo '<pre>';
print_r($records);
echo '</pre>';
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use IP2LocationLaravel; //use IP2LocationLaravel class
class TestController extends Controller
{
//Create a lookup function for display
public function lookup(){
var_dump(IP2LocationLaravel::isIpv4('8.8.8.8'));echo '<br>';
var_dump(IP2LocationLaravel::isIpv6('2001:4860:4860::8888'));echo '<br>';
print_r(IP2LocationLaravel::ipv4ToDecimal('8.8.8.8'));echo '<br>';
print_r(IP2LocationLaravel::decimalToIpv4(134744072));echo '<br>';
print_r(IP2LocationLaravel::ipv6ToDecimal('2001:4860:4860::8888'));echo '<br>';
print_r(IP2LocationLaravel::decimalToIpv6('42541956123769884636017138956568135816'));echo '<br>';
print_r(IP2LocationLaravel::ipv4ToCidr('8.0.0.0', '8.255.255.255'));echo '<br>';
print_r(IP2LocationLaravel::cidrToIpv4('8.0.0.0/8'));echo '<br>';
print_r(IP2LocationLaravel::ipv6ToCidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff'));echo '<br>';
print_r(IP2LocationLaravel::cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64'));echo '<br>';
print_r(IP2LocationLaravel::compressIpv6('2002:0000:0000:1234:FFFF:FFFF:FFFF:FFFF'));echo '<br>';
print_r(IP2LocationLaravel::expandIpv6('2002::1234:FFFF:FFFF:FFFF:FFFF'));echo '<br>';
}
}
php artisan make:controller TestController
return [
'IP2LocationioAPIKey' => 'your_api_key', // Required. Your IP2Location.io API key.
'IP2LocationioLanguage' => 'en', // Optional. Refer to https://www.ip2location.io/ip2location-documentation for available languages.
];
php artisan make:controller TestController
php artisan make:controller TestController
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.