A small piece of anti-spam JavaScript code

I found out that there was a spam in my Blog several days ago and I deleted it manually. The spam is created by MoableType’s comment system. Although MovableType has great anti-spam features. It blocked most of them, but it seems that there are some exceptions. My site is very small though, the spam still came up. I can imagine the serious problem when the traffic of my site increases. so I made some change in my site’s comment system.


I guess the spam does in this way: Crawl a HTML Page, then find the action and the textbox and automatically post a predefined comment.So the most used anti-spam technical is add a picture with blured/twisted/dotted text that only human beings can recognize around the post button. The drawback of this kind of technology in anti-spam is it is very unconvenience for normal commenters.

I would like to introduce my struggles of fightting with the spams. Firstly, I changed the name of the default MovableType comment script “mt-comments.cgi” on my server :

mt-comments-zxq.cgi

Then I changed the individual Entry Archive Template of MovableType. Here is the piece of changed code:

<form method="post" action="<$MTCGIPath$><$MTCommentScript$>" name="comments_form"
onsubmit="if (this.bakecookie.checked) rememberMe(this)">
<input type="hidden" name="static" value="1" />
<input type="hidden" name="entry_id" value="<$MTEntryID$>" />
<script type="text/javascript" language="javascript">
var s1 = "<$MTCGIPath$>";
var s2 = "mt-comments-zxq.cgi";
document.comments_form.action= s1 + s2;
</script>

The action of the comment post form is still mt-comments.cgi, which does not exist. Actually the JavaScript code will change the action of the form to the real path of my comment script.
But there is still a disadvantage in this code, that is, if the Browser doesn’t support JavaScript or turn it off, then he or she can not comment on my site. But I guess most of the modern browsers support JavaScript.

3 Replies to “A small piece of anti-spam JavaScript code”

Leave a Reply

Your email address will not be published. Required fields are marked *