Snippet · Mecha CMS

Code snippet collection for developers.

Block Users by IP Address

Author: Taufik Nurrohman · 301 Views

Tweet

Block users and visitors by their IP addresses.

$ip = Get::ip('unknown'); // Current IP address
$ip_x = ['123.456.123.456', '456.789.456.789']; // List of IP address(es) you want to block

if (Is::this($ip_x)->contain($ip)) {
    HTTP::status(403); // Forbidden
    Guardian::abort('Blocked user with IP <code>' . $ip . '</code>.');
}

0 Comments

No comments yet.