PHP code example of whois-api / simple-geoip

1. Go to this page and download the library: Download whois-api/simple-geoip 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/ */

    

whois-api / simple-geoip example snippets





WhoisApi\SimpleGeoip\Builders\ClientBuilder;


$builder = new ClientBuilder();

$client = $builder->build('your API_KEY');

try {
    echo $client->getRawData('8.8.8.8', 'json') . PHP_EOL;
    echo print_r($client->get('8.8.8.8'), 1) . PHP_EOL;
    
    $result = $client->get('1.1.1.1');
    echo 'IP: ' . $result->ip . PHP_EOL;
    echo 'Country: ' . $result->location->country . PHP_EOL;
    echo 'Region: ' . $result->location->region . PHP_EOL;
    echo 'City: ' . $result->location->city . PHP_EOL;
    echo 'Latitude: ' . $result->location->lat . PHP_EOL;
    echo 'Longitude: ' . $result->location->lng . PHP_EOL;
    echo 'Postal Code: ' . $result->location->postalCode . PHP_EOL;
    echo 'Timezone: ' . $result->location->timezone . PHP_EOL;
} catch (\Throwable $exception) {
    echo "Error: {$exception->getCode()} {$exception->getMessage()}" . PHP_EOL;
}