PHP code example of ysenn / ip2region

1. Go to this page and download the library: Download ysenn/ip2region 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/ */

    

ysenn / ip2region example snippets


// First use
// View command help
// Initialize the IP database
php vendor/ysenn/ip2region/db_download.php -h


// ip2region
use IP2Region\IP2Region;

// IPv4-only support
$ip2region = new IP2Region();
// ip database file loading methods
// $ip2region->loadDBModel(IP2Region::VECTOR_INDEX);
// loading ip database file
$ip2region->loadDBFile();
// output raw data
//$ip2region->outputRawData();
return $ip2region->search('127.0.0.1');


// ip2location
use IP2Region\IP2Location;

// Dual-stack support
$ip2location = new IP2Location();
// loading ip database file
$ip2location->loadDBFile();
// output raw data
//$ip2location->outputRawData();
return $ip2location->search('127.0.0.1');
//return $ip2location->search('2001:0db8:85a3:0000:0000:8a2e:0370:7334'); // ipv6