Forum Moderators: phranque

Message Too Old, No Replies

How to Prevent DoS Against a Particular Link

         

foxfox

1:21 pm on Nov 11, 2007 (gmt 0)

10+ Year Member



Are there any module can help to prevent DOS against a particular link, e.g. login.php, I want to limit 1 request per client per second.

pontifex

11:41 pm on Nov 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi, if you have a xy.php page taking the requests, i would suggest, that you write out a log for that and forbid heavy usage with something like that:

<?php
// initialize vars
$lastipsarray=array();
$counter=0;

// open list of last ips
$lastipsfhd=fopen("path/to/lastips.txt","r");

// read them in
while(!feof($lastipsfhd))
{
$last100ips[]=str_replace("\n","",fgets($lastipsfhd));
}

$userip=getenv("REMOTE_ADDR");

if(array_search($userip,$last100ips))
{
$userisallowed=-1;
fclose($lastipsfhd);
print "quitting for heavy usage, please come back in a few seconds...";
exit;
}
else
{
fclose($lastipsfhd);
// write out IPs
$userisallowed=1;
}
// HERE YOUR CODE FOR ALLOWED USERS!
?>

that code needs some completion, but if you write out the IPs there and keep a backlog of around 100 ips, that should help?

Regards,
P!

foxfox

2:19 pm on Nov 12, 2007 (gmt 0)

10+ Year Member



I think the code above will lead to another overhead.