2014-06-06 91 views
0

我正在制作一个简单的网络聊天应用程序。 它看起来像这样:Ajax垃圾邮件发送过滤器

<?php 
session_start(); 
if(!isset($_SESSION['login'])) 
{ 
    Header('Location: /'); 
    die(); 
} 

?> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script> 
<style> 
    #update { 
    width: 550px; 
    height: 300px; 
    padding: 10px; 
    border: 2px groove gray; 
    overflow:scroll; 
    margin: 10px; 
     margin-right: auto; 
    } 
    </style> 
    </head> 
    <a href="logout.php">Log out</a> 
    <center> 
    <h2>Uchat Alpha</h2> 
    </center> 
    <script> 


$(document).ready(function() { 
    setInterval(function() { 
     $.get("chatloader.php", function (result) { 
      $('#update').html(result); 
     }); 
    }, 100); 
}); 

$('#ajaxform').submit(function(){ 
    $(':submit', this).click(function() { 
     return false; 
    }); 
}); 

$(document).ready(function() { 
      // bind 'myForm' and provide a simple callback function 
      $('#ajaxform').ajaxForm(function() { 
       $('#ajaxform')[0].reset(); 
     }); 
    }); 
</script> 

<div id="update"> 
</div> 
<center> 
<form name="ajaxform" id="ajaxform" action="http://retroamp.eu/uchat/chathandler.php" method="post"> 
    <input type="text" id="msg" name="msg" maxlength="50" value ="" placeholder="Message"/> 
    <input type="submit" value="Send"/> 
</form> 
</center> 

什么我的问题是,是人们能喜欢填满文字或链接任何聊天。

有没有一种方法可以防止这种情况而无需使用验证码。

我的想法是,你必须等3秒钟才能发送新消息,但是如何?

回答

0

虽然你可以在JS中这样做来限制用户在浏览器中......服务器端没有任何东西可以阻止他们创建自己的请求并使用它发送垃圾邮件,无论你的JS停止了什么他们不干。

您很可能需要PHP/JS中的双面解决方案来缓解这些问题。这不仅仅是一个JS在阻止它。