I've managed to implement the code for connecting to the IP database, and register failed attempts, with the corresponding user_id from users table, and also the IP address & timestamp.
I then query the database and it checks with a 10-minute interval to the last login attempt.
The user can just attempt another sign in attempt, and it logs that to the database.
I'm not sure what I have to now to limit the database being queried again after the 3 failed times?
What should I be looking up?
Code is:
function timestampCount($ip,$id,$mysqli): int
{
mysqli_query($mysqli, "INSERT INTO `ip` (`id`, `address` ,`timestamp`)VALUES ('$id','$ip',CURRENT_TIMESTAMP)");
$result = mysqli_query($mysqli, "SELECT COUNT(*) FROM `ip` WHERE `address` LIKE '$ip' AND `timestamp` > (now() - interval 10 minute)");
$count = mysqli_fetch_array($result, MYSQLI_NUM);
if($count[0] > 3){
echo "Your are allowed 3 attempts in 10 minutes";
return 1;
}
else {
return 0;
}
}
I then call that with
$attempts = (new ip_request)->timestampCount($ip, $id,$mysqli);
on my login page.
As I thought I might get a 1 or a 0, and then depending on which one, set the $hideLogin = true;, and work with something like that.
But every time the user refreshes the page, the variable is reset.
So I'm not sure what next to do with the login page to stop the database from being queried again for subsequent login attempts.