1. Go to this page and download the library: Download khaleejinfotech/ip2location 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/ */
khaleejinfotech / ip2location example snippets
return [
'api_key' => env('IP2LOCATION_API')
];
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Khaleejinfotech\IP2Location\IP2Location;
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
$ip2Location = new IP2Location();
$ip2Location->setIP('8.8.8.8');
$ip2Location->lookup();
$response = $ip2Location->getResponse();
echo 'IP Address : ' . $response->getIp() . "<br>";
echo 'Detect VPN : ' . $response->isVPN() . "<br>";
echo 'Detect Proxy : ' . $response->isProxy() . "<br>";
echo 'Detect Tor : ' . $response->isTor() . "<br>";
echo 'Country Code : ' . $response->getCountryCode() . "<br>";
echo 'Country Name : ' . $response->getCountryName() . "<br>";
echo 'Region Name : ' . $response->getRegionName() . "<br>";
echo 'Region Code : ' . $response->getRegionCode() . "<br>";
echo 'City Name : ' . $response->getCity() . "<br>";
echo 'Latitude : ' . $response->getLatitude() . "<br>";
echo 'Longitude : ' . $response->getLongitude() . "<br>";
echo 'Time Zone : ' . $response->getTimeZone() . "<br>";
}
}
php artisan vendor:publish --tag="ip2location"
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.