[英]Honeypot PHP for Comment Form
I am creating a jquery ajax popup comment form, but am having a problem with the way Im setting up my "honeypot" in php. 我正在创建一个jquery ajax弹出注释表单,但我在php中设置我的“honeypot”的方式有问题。
The honeypot ($robotest) isn't working; 蜜罐($ robotest)无效; instead the script returns "E-mail is not correct".
而是脚本返回“电子邮件不正确”。 Can anyone point out my error?
任何人都能指出我的错误吗? Thank you
谢谢
The html form is: html表单是:
<form class="cmxform" id="commentForm" method="POST" action="">
<p>
<label for="cname">Name</label>
<input id="cname" name="name" size="25" class="required" minlength="2" />
</p>
<p>
<label for="cemail">E-Mail</label>
<input id="cemail" name="email" size="25" class="required email" />
</p>
<p>
<label for="curl">URL</label>
<input id="curl" name="url" size="25" class="url" value="" />
</p>
<p>
<label for="ccomment">Your comment</label>
<textarea id="ccomment" name="comment" cols="22" class="required"></textarea>
</p>
<p class="robotic" id="pot">
<label>Please leave this blank:</label>
<input name="robotest" type="text" id="robotest" class="robotest" />
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
EDIT: 编辑:
Thanks to @JamWaffles for the support. 感谢@JamWaffles的支持。 Below is the correct way to implement the honeypot.
以下是实现蜜罐的正确方法。 (And as Kamalo noted you will want to have the id of 'robotest' set to display:none in your css):
(正如Kamalo所说,你会希望将'robotest'的id设置为显示:你的css中没有:)
<?php
$robotest = $_POST['robotest'];
$email = $_POST['email'];
if((!filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) {
print "E-mail is correct";
$to = 'asdfdsafasdfsda@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com';
mail($to, $subject, $message, $headers);
} else {
print "E-mail is not correct";
}
?>
filter_var()
returns a non-falsy value when the email is valid, not false
. filter_var()
在电子邮件有效时返回非虚假值,而不是false
。 Remove the !
删除
!
before filter_var(
in your if()
: 在
filter_var(
之前filter_var(
在你的if()
:
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest = ""))
You're executing code inside the if()
when filter_var()
fails , which is why you're getting 当
filter_var()
失败时 ,你在if()
执行代码,这就是你得到的原因
E-mail is not correct
电子邮件不正确
for valid emails. 有效的电子邮件。
Something else I missed too is the fact you're assigning to $robotest
instead of comparing it against an empty string. 我错过的其他东西是你分配给
$robotest
而不是将它与空字符串进行比较的事实。 You need to use the double equals comparison operator instead of the single equals assignment operator. 您需要使用double equals比较运算符而不是单个equals赋值运算符。 Your
if()
should look like this: 你的
if()
应该是这样的:
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == ""))
对于另一个答案,我在我的html中设置了一个“蜜罐”输入,显示:无
<input type="text" name="honeypot" id="honeypot" style="display:none;"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.