阻止用户在浏览器控制台中循环Ajax请求

时间:2019-06-05 09:33:39

标签: php jquery mysql

我的网站目前存在一个小的安全性问题。我进行了一次公共聊天,该聊天使用Ajax发布到一个php文件,然后由该文件处理并将该聊天消息发送到数据库。然后将其返回到js文件并显示。但是我遇到的一个问题是,用户可以设置一个间隔循环,然后将无限的ajax请求发送到我的数据库,然后用随机消息将其过载。

我尝试限制每分钟可以发送消息的时间,但是这没有实际用途。这是负责发送AJAX请求的Javascript代码。如果需要提供PHP,可以提供。

var spammI = 0;

function sendChat(message) {
  window.setTimeout(function() {
    spammI = 0;
  }, 3000);

  if (spammI != 1) {
    $.ajax({
      type: 'POST',
      dataType: 'json',
      url: 'handlers/ajax.php?command=new_message',
      data: {
        message: message
      },
    });
    clearInput();
    spammI = 1;
  } else {
    alert("Messages can only be sent once every 3 seconds!");
  }
};

function loadChat() {
  $.ajax({
    type: 'POST',
    dataType: 'json',
    url: 'handlers/ajax.php?command=load_message',
    data: {
      loadChat: "Load"
    },
    success: function(response) {
      insertData(response);
    }
  })
}

我真的希望这里的人能找到解决方案,因为这对我来说是一个很大的问题。

0 个答案:

没有答案