Saturday, September 13, 2008

Banning SPAN in coldfusion

Banning the spam
Internet spam is on the rise and more importantly spammers are targeting your site's comment forms.

They are looking for the trackback urls to fool search engines into ranking their website higher in the search results.

When this started to happen to me, I wanted to sent out emails to the offenders demanding that they stop.

Unfortunatly the spam is being generated by bots and programs not some pimple faced kid behind a keyboard.

Banning IP addresses is not enough and rarely works since intelligent spammers hide their true identity anyway.

Next approach...

Banning Keywords used by the offending sites. Thats where this tutorial comes in.

<!--- DEFINE BANNED WORDS LIST --->
<cfset BannedWordsList = "poker,casino,roulette,tournament,backgammon,vegas,gambling,baccarat,vigorish">

<!--- SET NAUGHTY POSTER VALUE TO 0 --->
<cfset naughty = 0>

<!--- LOOP OVER FORM FIELDS AND CHECK ALL FIELDS FOR BANNED WORDS SET NAUGHTY POSTER TO 1 IF BANNED WORDS WERE FOUND PERIOD --->

<cfloop index="thefield" list="#form.fieldnames#">
<cfif ListFindNoCase(BannedWordsList, Evaluate(TheField), ",")>
<cfset naughty = 1>
</cfif>
</cfloop>

<!--- IF BANNED WORDS WERE FOUND GIVE AN ERROR AND ABORT PROCESSING --->
<cfif naughty EQ 1>
<h1>ERROR</h1>
<p>You have entered a keyword that has now been banned from this site.</p>
<p>please <a href="javascript:history.go(-1);">Go back</a> and correct obvious words.</p>
<cfabort>
</cfif>

No comments: