Quick and easy flood protection?

后端 未结 7 1883
忘了有多久
忘了有多久 2020-12-29 11:51

I have a site where a user submits a message using AJAX to a file called like.php. In this file the users message is submitted to a database and it then sends a

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 12:21

    If you want to stop flooding a search page you can try it like this way:

    $flood_protection_interval = 2;
    session_start();
    if(
        isset($_SESSION['ip']) && 
        $_SESSION['counter'] > 10 &&
        $_SESSION['last_post'] + $flood_protection_interval > time()
        ){
            // $_SESSION['counter'] = 0; // Use this if you want to reset counter
            die("
    \n\n\n\tFLOOD PROTECTION");
    }
    $_SESSION['counter']++;
    $_SESSION['last_post'] = time();
    $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
    

    So if your visitor search 10 times under e.g. 2 seconds he will be stopped!

提交回复
热议问题