Files
html/api/rate-limiter.php
2026-04-12 22:57:03 +02:00

3 lines
326 B
PHP

<?php
$ip=$_SERVER["REMOTE_ADDR"]??"0";$k="/dev/shm/rl_".md5($ip.basename($_SERVER["SCRIPT_NAME"]));$n=time();$d=@json_decode(@file_get_contents($k),1);if($d&&$d["t"]>$n-60&&$d["c"]>=60){http_response_code(429);die("rate limit");}if($d&&$d["t"]>$n-60)$d["c"]++;else $d=["t"=>$n,"c"=>1];@file_put_contents($k,json_encode($d));