PHP code example of ip-api-io / ipapi-php
1. Go to this page and download the library: Download ip-api-io/ipapi-php 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/ */
ip-api-io / ipapi-php example snippets
use IpApiIo\Client;
$client = new Client(apiKey: 'YOUR_API_KEY'); // free key at https://ip-api.io
// Where is this IP, and is it risky?
$info = $client->lookup('8.8.8.8');
echo $info['location']['country']; // "United States"
var_dump($info['suspicious_factors']['is_vpn']); // false
$risk = $client->riskScore('8.8.8.8');
echo "{$risk['score']} {$risk['risk_level']}"; // 0 low
$email = $client->validateEmail('[email protected]');
echo $email['reachable']; // "yes"
use IpApiIo\AuthenticationError;
use IpApiIo\RateLimitError;
try {
$client->lookup('8.8.8.8');
} catch (RateLimitError $e) {
echo "limit={$e->limit} remaining={$e->remaining} resets_at={$e->reset}";
} catch (AuthenticationError $e) {
echo 'invalid API key';
}