PHP code example of ip2geo-dev / sdk

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

    

ip2geo-dev / sdk example snippets


use Ip2Geo\Ip2Geo;

Ip2Geo::init('your-api-key');

Ip2Geo::init('your-api-key', [
    'version_update_message' => true,
    'cache'                  => true,
    'cache_max_size'         => 1000,
    'cache_ttl'              => 300,
]);

use Ip2Geo\Ip2Geo;

$convertedIp = Ip2Geo::convertIp('8.8.8.8');

$convertedIps = Ip2Geo::convertIps([
    '8.8.8.8',
    '1.1.1.1',
    '9.9.9.9',
    '64.6.64.6',
]);

// [
//     'success' => true,
//     'code'    => 200,
//     'message' => 'Success',
//     'data'    => [ ... ],
//     '_req'    => [
//         'reqId'   => 'string',
//         'resTime' => 123,
//     ],
// ]

$conversion  = Ip2Geo::getConversion('conversion-id');
$conversions = Ip2Geo::getConversions(['id-a', 'id-b']);
$list        = Ip2Geo::listConversions(0, 50);

$conversion = Ip2Geo::getConversion('conversion-id', [
    Ip2Geo::SELECT['IP'],
    Ip2Geo::SELECT['COUNTRY_NAME'],
]);

$result = Ip2Geo::ipValidation('8.8.8.8');
// ['ip4' => true, 'ip6' => false]