doumeng1143 2013-02-07 04:22
浏览 4
已采纳

如何使用PHP / Javascript检查24小时内存在“错误”的次数

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.

  • 写回答

1条回答 默认 最新

  • 普通网友 2013-02-07 04:31
    关注

    This is a good candidate for a database. You could have a table with 3 fields : IPAddress, Attemps, LastDate so 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:

    if (same date) {
        if (attemps < 5) {
            if (!try_connect()) {
                attemps++;
            }
        } else {
            error();
        }
    } else { // different date
        attemps = 1;
    }
    
    lastDate = actualDate;
    

    Hope this helps :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分