Setup and Installation of Zen Firewall for PHP
1
5
Enable Rate limiting and User blocking
// Check if Aikido extension is loaded
if (extension_loaded('aikido')) {
// Get the user from your authentication middleware
// or wherever you store the user
\aikido\set_user("123", "John Doe");
// Check blocking decision from Aikido
// and decide on what to do
$decision = \aikido\should_block_request();
if ($decision->block) {
if ($decision->type == "blocked") {
if ($decision->trigger == "user") {
return response('Your user is blocked!', 403);
}
else if ($decision->trigger == "ip") {
return response("Your IP ({$decision->ip}) is blocked due to: {$decision->description}!", 403);
}
} else if ($decision->type == "ratelimited") {
if ($decision->trigger == "user") {
return response('Your user exceeded the rate limit for this endpoint!', 429);
}
else if ($decision->trigger == "ip") {
return response("Your IP ({$decision->ip}) exceeded the rate limit for this endpoint!", 429);
}
}
}
}6
Troubleshooting
Last updated
Was this helpful?




