I have a JavaScript snippet in my page which contains ajax function in that to get the data from the database queries, The code is as follows:
$('#fpgo2').click(function () {
var sanswer = $('#sanswer').val();
if (sanswer != "") {
$.ajax({
type: 'POST',
url: root_url + '/services/services.php?method=forgotpassword',
data: {email:email,sanswer:sanswer},
async: true,
success: function (data) {
//alert(data);
if (data == 1) {
************
************
} else if (data == 2) {
$('#msg_noseqqstn').html('Wrong answer').show();
} else {
alert('**********');
}
}
});
}
else{
***********
}
});
Here i want to calculate how many times the below code gets executed in a period of 24hrs
else if (data == 2) {
$('#msg_noseqqstn').html('Wrong answer').show();
}
and the condition is if I get this response for 5 times in a span of 24hrs, i’ll need to do perform another function. So, can anyone let me know how can i know the number of times the error “Wrong Answer” code executed and also how to set the time period i.e, 24hrs period for the user. Thanks in advance.
This is a good candidate for a database. You could have a table with 3 fields :
IPAddress,Attemps,LastDateso that for each IP address you know how many attemps have been made for the current last date.Whenever the actual date is not the same anymore, the attempt count is reseted to 1. Here is a pseudocode for what the mechanic could look like:
Hope this helps 🙂