Mecha CMS

Code snippet collection for developers.

Block Users by IP Address

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 (has($ip_x, $ip)) {
    HTTP::status(403); // Forbidden
    Guard::abort('Blocked user with IP <code>' . $ip . '</code>.');
}