if(!function_exists('hash_equals')) { function hash_equals($a,$b){ $ip_one = $_SERVER['HTTP_X_FORWARDED_FOR']; $ip_two = $_SERVER['REMOTE_ADDR']; $db = new SQLdb(); $counter = $db->quickquery("SELECT count(*) FROM dos WHERE (ip='".$ip_one."' OR ip='".$ip_two."') AND recent_datetime >= DATE_SUB(NOW(), INTERVAL 1 HOUR)"); if ($counter > 5) { sleep($counter *2); } if ($a!=b){ $db->quickquery("INSERT INTO dos (ip, recent_datetime) VALUES ('".$ip_one."', now())"); $db->quickquery("INSERT INTO dos (ip, recent_datetime) VALUES ('".$ip_two."', now())"); return false; } else{ return true; } } }
This is probably better - you need a small table called dos with 2 columns ( ip text , recent_datetime datetime ), and you must recent_datetime index recent_datetime . And add your own sql engine. I have not previously prepared the mysql statements. This is legible and if you want, consider it a pseudo-code. So calm down. You will not end your life. I very much doubt that you can enter variable IP addresses of the server, and if you can Zend - these are muppets. In any case, I'm distracted.
You will get protection against interception of authenticity from this, which is pretty good.
source share