我希望通过使用here所述的网络表单混淆方法来捕获垃圾邮件发送者。
唯一的问题是我在ColdFusion服务器上,我的mailto
表单在cfm中。
if( !isset($_POST['name'])) { die("No Direct Access"); } // Make sure the form has actually been submitted
$name = $_POST['name'];
$email = $_POST['email'];
$spam = $_POST['username']; // This is our Honeypot field
if($spam) { // If the Honeypot field has been filled in
die("No spamming allowed!");
} else {
// Process the form like normal
}
(更新:评论代码)
我的表格:
<tr style="display: none;">
<td> <li id="user" style="display: none;">
<label for="spamCatch">spamCatch</label>
<input type="text" name="spamCatch">
</li>
</td>
</tr>
我的邮件cfm:
<cfparam name="form.Notform1" default="">
<cfset spam = false>
<cfif structKeyExists(form,'name')>
<cfset spamCheck = form.spamCheck>
<cfif spam>
No spam.
<cfabort>
<cfelse>
<cfmail from="title" to="email" subject="subject" server="servername" type="html">
<style type="text/css">
<cfinclude template="../css/cfForms.css">
</style>
HTML HERE FROM FORM
</cfmail>
</cfif>
</cfif>
答案 0 :(得分:1)
这是基本概念。我强烈建议查看learncfinaweek.com
<cfset spam = false>
// run code to check for spam
<cfif structKeyExists(form,'name')>
<cfset name = form.name>
<cfset email = form.email>
<cfset username = form.username>
<cfif spam>
No spam.<cfabort>
<cfelse>
<cfmail to="email" from="email" subject="email">
text
</cfmail>
</cfif>
<cfelse>
No Direct Access.<cfabort>
</cfif>
答案 1 :(得分:0)
<cfif !structkeyexists(form, "name")>
<cfdump var="no direct access" abort>
</cfif>
<cfparam name="form.name" default="">
<cfparam name="form.email" default="">
<cfparam name="form.spam" default="">
<cfif len(form.spam)>
<cfdump var="No spamming allowed!" abort>
<cfelse>
</cfif>
答案 2 :(得分:0)
使用<cfset spam = len(trim(form.userName))>
请阅读以下内容以获取解释。
在PHP an empty string is considered false, and any string with a length is considered true中。 ColdFusion没有相同的隐式布尔转换。
// PHP
var_dump((bool) ""); // bool(false)
var_dump((bool) "foo"); // bool(true)
<!--- CFML --->
yesNoFormat("") <!--- ERROR: cannot convert the value "''" to a boolean --->
yesNoFormat("foo") <!--- ERROR: cannot convert the value "foo" to a boolean --->
$spam = $_POST['username'];
if($spam){}
与
相同<cfset spam = form.userName>
<cfif spam></cfif>
如果表单字段为空,将产生相同的无法将值“'”转换为布尔错误,您希望它是。
您要做的是检查蜂蜜罐字段的长度或检查空字符串。
<cfif len(trim(form.userName))>
<!--- or <cfif trim(form.userName) neq ""> --->
no spam <cfabort>
</cfif>
如果您仍想使用垃圾邮件变量,可以执行以下操作:
<cfset spam = len(trim(form.userName))>
<cfif spam>
No spam<cfabort>
</cfif>
现在你有<cfset spam = false>
但是代码没有做任何改变布尔值的事情。如果您将该行更改为<cfset spam = len(trim(form.userName))>
,那么您的代码将有效。