0) $iptime = 20; // minimum number of seconds between visits for users with certain cookie
else $iptime = 10; // minimum number of seconds between visits for everyone else
$ippenalty = 60; // seconds before visitor is allowed back
if($cookie && $othercookie > 0)$ipmaxvisit = 30; // maximum visits, per $iptime segment
else $ipmaxvisit = 20; // maximum visits per $iptime segment
Sorry, but it's not a solution.
If you're need protection, then you'll should setup hardware firewall or use CDN services.
Such as Cloudflare, Cloud Front, etc.