PHP code example of ip2location / ip2proxy-laravel

1. Go to this page and download the library: Download ip2location/ip2proxy-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 / ip2proxy-laravel example snippets




namespace App\Http\Controllers;

use Illuminate\Http\Request;
use IP2ProxyLaravel;            //use IP2ProxyLaravel class

class TestController extends Controller
{
    //Create a lookup function for display
    public function lookup(){
        //Try query the geolocation information of 1.2.3.4 IP address
        $records = IP2ProxyLaravel::get('1.2.3.4', 'bin');

        echo '<p><strong>IP Address: </strong>' . $records['ipAddress'] . '</p>';
        echo '<p><strong>IP Number: </strong>' . $records['ipNumber'] . '</p>';
        echo '<p><strong>IP Version: </strong>' . $records['ipVersion'] . '</p>';
        echo '<p><strong>Country Code: </strong>' . $records['countryCode'] . '</p>';
        echo '<p><strong>Country: </strong>' . $records['countryName'] . '</p>';
        echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>';
        echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>';
        echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';
        echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>';
        echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>';
        echo '<p><strong>Domain: </strong>' . $records['domain'] . '</p>';
        echo '<p><strong>Usage Type: </strong>' . $records['usageType'] . '</p>';
        echo '<p><strong>ASN: </strong>' . $records['asn'] . '</p>';
        echo '<p><strong>AS: </strong>' . $records['as'] . '</p>';
        echo '<p><strong>Last Seen: </strong>' . $records['lastSeen'] . '</p>';
        echo '<p><strong>Threat: </strong>' . $records['threat'] . '</p>';
        echo '<p><strong>Provider: </strong>' . $records['provider'] . '</p>';
    }
}


return [
    'IP2ProxyAPIKey' => 'your_api_key', // Required. Your IP2Proxy API key.
    'IP2ProxyPackage' => 'PX1', // Required. Choose the package you would like to use.
    'IP2ProxyUsessl' => false, // Optional. Use https or http.
];



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use IP2ProxyLaravel;            //use IP2ProxyLaravel class

class TestController extends Controller
{
    //Create a lookup function for display
    public function lookup(){
        //Try query the geolocation information of 1.2.3.4 IP address
        $records = IP2ProxyLaravel::get('1.2.3.4', 'ws');

        echo '<pre>';
        print_r($records);
        echo '</pre>';
    }
}


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