我知道之前已经问过这个问题,但我在其他任何地方都没有看到以下解决方案。
我有一个包含很多表单的网站,我正在寻找一种方法,而不需要为每个表单编辑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();
}
});
});
如果机器人知道“点击”,我想这会失败。按钮,但我不知道是不是这样?
答案 0 :(得分:1)
这真的不能阻止机器人,这就是原因。机器人将进入并从您的表单中删除字段名称,然后制作自己的POST请求。他们不会去看,更不用说服从你的JavaScript事件了。
你应该做的是制作一个AJAX页面并让你的表单以这种方式提交。它使机器人更难以填写并提交,因为没有<form action="page.php">
可以跟随。另一种方法是安装验证码,如ReCaptcha