I want to develop a security system, which serves both contact form and login, the intention is that it is an addition to the use of CAPTCHA, or in some cases a substitute. The logic is as follows:
The user can access a maximum of 4 times for intervals of 7 seconds, if he accesses more than 4 times that particular page of data within 7 seconds, the system understands how a bot and redirects the user to another location to "divert" traffic or perform other security measures.
This was the experimental code I developed along with some friends.
NOTE 1: I'm not a PHP expert, I'm always in constant learning, so tips and methodologies are always welcome.
NOTE 2: The idea is to redirect bots to avoid sending spam or even attacks like brute force , so it's a code generic for use in several cases
<?php
// Detecta BOT
session_start();
$maxTempoLim = 7; //Tempo Limite
$maxVezesLim = 4; //Numero de Vezes possiveis dentro do tempo limite
if ( ! isset($_SESSION['temp_bot'])) {
$_SESSION['temp_bot'] = time();
$_SESSION['conta_vezbot'] = 1;
}
$diferenTime = time() - $_SESSION['temp_bot'];
if ($diferenTime <= $maxTempoLim) {
$_SESSION['conta_vezbot']++;
if ($_SESSION['conta_vezbot'] > $maxVezesLim) {
session_destroy();
header('Location: spam_detectado.php'); //redireciona
// ou colocar outra ação ao invés de redirecionar
exit;
}
}
The idea came from a situation where they tried to send spam to a contact form on my page and from some clients, I both added a CAPTCHA and it worked very well, but I did not want to force the user to type the CAPTCHA , I would like to create something that detects that it is a bot or any other type of system accessing uninterruptedly, and through the amount of access per second, or for a period of time that for an ordinary user would be impossible, redirect traffic.