isipsafe
PHP logo

PHP

Check and report from any PHP application.

Works in any PHP application with the curl extension, which is nearly all of them. For WordPress there is a ready-made must-use plugin.

Check an address

function isipsafe_score(string $ip): int {
    $ch = curl_init('https://isipsafe.com/api/v1/check?ip=' . urlencode($ip));
    curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 3]);
    $body = curl_exec($ch);
    curl_close($ch);
    $data = json_decode((string) $body, true);
    return (int) ($data['data']['abuseConfidenceScore'] ?? 0); // 0 if the lookup failed
}

if (isipsafe_score($_SERVER['REMOTE_ADDR']) >= 75) {
    http_response_code(403);
    exit('Access denied');
}

Report an address

function isipsafe_report(string $ip, string $categories, string $comment = ''): void {
    $ch = curl_init('https://isipsafe.com/api/v1/report?key=' . urlencode(getenv('ISIPSAFE_KEY') ?: ''));
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => http_build_query(['ip' => $ip, 'categories' => $categories, 'comment' => $comment]),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 5,
    ]);
    curl_exec($ch);
    curl_close($ch);
}

isipsafe_report('203.0.113.50', 'web-app-attack,brute-force', '40 failed logins in 5 minutes');

Need a hand?

If something here does not work with your version of PHP, or you have improved it, tell us. We update these pages with what people send.

PHP and its logo are trademarks of their respective owners. isipsafe is not affiliated with or endorsed by them.