我知道这个问题之前已经被问过,但我在其他地方没有看到以下解决方案。
我有一个包含很多表单的网站,我正在寻找一种方法来抵御机器人,而无需为每个表单编辑 php。
我打算使用这个,但我想知道是否有人有任何想法或理由为什么我不应该使用它?
<form method="POST" action="enableJavascript.html">
<!-- I change the action to a page to tell the user
that javascript is required-->
<input name="action" value="contact.php" type="hidden"/>
<!-- and add an input that contains the original action-->
<input name="name"/>
<input name="email"/>
<input type="submit" value="submit"/>
</form>
这是处理表单发布的 javascript/jQuery:
$(function() {
$('form').submit(function(e) {
var $this = $(this);
if (e.originalEvent) { // only change the action if the form was
// submitted via user input
e.preventDefault();
$this.attr('action', $('input[name=action]',$this).val());
$this.submit();
}
});
});
我想如果机器人会“点击”按钮,这就会失败,但我不知道情况是否如此?
最佳答案
这确实无法阻止机器人,原因如下。机器人会进来并从您的表单中抓取字段名称,然后制作自己的 POST 请求。他们不会看到,更不用说遵守您的 JavaScript 事件停止了。
您应该做的是制作一个 AJAX 页面并让您的表单以这种方式提交。这使得机器人更难填写并提交,因为没有 <form action="page.php">
跟随。另一种方法是安装验证码,例如 ReCaptcha
关于javascript - 另一种预防垃圾邮件机器人的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25447110/