$ip, 'timestamp' => strtotime($timestamp)]; } } // Vérifier si l'IP est déjà blacklistée $blacklisted = false; if (file_exists($blacklist_file)) { $blacklisted_ips = file($blacklist_file, FILE_IGNORE_NEW_LINES); $blacklisted = in_array($visitor_ip, $blacklisted_ips); } // Ajouter une nouvelle tentative file_put_contents($log_file, "$visitor_ip," . date('Y-m-d H:i:s') . ", " . $_SERVER["REQUEST_METHOD"] . "," . getFullUrl() . "\n", FILE_APPEND); // Compter les tentatives récentes $now = time(); $recent_attempts = array_filter($attempts, function ($attempt) use ($visitor_ip, $now, $time_window) { return $attempt['ip'] === $visitor_ip && ($now - $attempt['timestamp']) <= $time_window; }); if (count($recent_attempts) + 1 > $max_attempts && !$blacklisted) { file_put_contents($blacklist_file, "$visitor_ip\n", FILE_APPEND); $blacklisted = true; } if ($blacklisted) { header('HTTP/1.0 401 Unauthorized'); echo "Votre IP ($visitor_ip) a été blacklistée pour trop de tentatives."; exit(); } else { echo "Votre IP est : $visitor_ip. Nombre de tentatives récentes : " . (count($recent_attempts) + 1); } } else { echo json_encode([["error" => "404"]]); } */ error_reporting(E_ALL); ini_set('display_errors', 'On'); require_once "../core/class/blacklist.class.php"; new blacklist; if(blacklist::isValidIPv4()){ blacklist::execute("404"); } else { echo json_encode([["error" => "404"]]); } ?>