Flood protection

I have a problem with flood protection; when it’s enabled, it throws errors. Here are the codes.

if(!in_array(ICPConnect::get_client_ip(),array_merge($AllowedIps, $rangeMercadoPagoIps)) || strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'googlebot') === false){
			$FloodProtection = new FloodProtection('ICPNetworks', 45, 60, null, false);	
			if($FloodProtection->check(ICPConnect::get_client_ip())){
				header("HTTP/1.1 429 Too Many Requests");
				exit("
					<html>
						<title>GamesAddicts - Flood Protection</title>
						<body style=\"text-align:center;\">
							<h1>Games Addicts Flood Protection</h1><br>
							<img src=\"images/miscs/what.jfif\"><br>
							<h3>Your IP ".ICPConnect::get_client_ip()." has been blocked!</h3>
							Wait a few seconds and try to access again.<br><br>
</body>
					</html>
				");
			}
		}

Error

Fatal error: Uncaught Error: Call to undefined function frdl\security\floodprotection\get_current_user() in /home/vol3_7/infinityfree.com/if0_35690765/htdocs/engine/classes/FloodProtection.php:68 Stack trace: 
#0 /home/vol3_7/infinityfree.com/if0_35690765/htdocs/engine/classes/FloodProtection.php(24): frdl\security\floodprotection\FloodProtection->getCacheDir('FRDL-FLOODPROTE...') 
#1 /home/vol3_7/infinityfree.com/if0_35690765/htdocs/engine/classes/ICP_Connect.php(125): frdl\security\floodprotection\FloodProtection->__construct('ICPNetworks', 45, 60, NULL, false) 
#2 /home/vol3_7/infinityfree.com/if0_35690765/htdocs/engine/connect.php(15): ICPConnect::connect('game', true, 'remotmysqlIP', 'remotemysqldb', 'remotmysqluser', 'remotmysqlpass') 
#3 /home/vol3_7/infinityfree.com/if0_35690765/htdocs/index.php(18): require_once('/home/vol3_7/in...') 
#4 {main} thrown in /home/vol3_7/infinityfree.com/if0_35690765/htdocs/engine/classes/FloodProtection.php on line 68

Could someone help me solve it?

Hello

Do note that because you are doing this on the server itself, each load will still generate multiple hits (The PHP page(s) and the image), and will still use server resources.

It is a much better idea to use something like CloudFlare that has built-in rate limiting.

8 Likes

get_current_user is a native PHP function, which is disabled on free hosting:
https://www.php.net/manual/en/function.get-current-user.php

I’d recommend following the approach @Greenreader9 suggests, but if you insist on using this script, you’ll need to find the line where get_current_user is called in engine/classes/FloodProtection.php, and see how you can change it to work.

8 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.