Very *effective* antispam trick on blogs

21 Oct

Most of bloggers have a problem with spam. Of course, there is Akismet, but sometimes Akismet is not good enough because he doesn’t catch all spam messages. So, with this in mind, i wanted only to get rid of all automated messages.

So, look what i did:

First of all, i go with „robots fills ALL fields with something” in my mind. I’ve added only TWO lines of code: one in comments.php from your theme folder and one in wp-comments-post.php from your root folder.

Ok, how you do it?

First of all you need a ftp client and a text editor. E-texteditor is 2 in 1 so you can download a trial version for doing this. Ofcourse, you can use the old and ugly notepad (or whatever your OS has default).

Open comments.php (which is in your wp-content/themes/your_theme_name folder) then find this line:

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

Some things can vary (like ID of the form), but 90% in cases you won’t need to look for something else ;)

Just AFTER this line you add:

<p style="position:absolute; left:-9999px;">Don't fill this! <input type="text" name="name2" /></p>

We put a form here and hide it. I didn’t use display:none because i wanted to be sure that field will be showed up, even is on the left side of the screen (you should actually turn you head to left to see it :P ) So the bot will actually SEE that form and will fill. Normal user won’t.

Save and upload (or just save if you work directly on ftp) then open wp-comments-post.php from your root folder. Just after the

<?php
/**
 * Handles Comment Post to WordPress and prevents duplicate comment posting.
 *
 * @package WordPress
 */

beginning part, just add this:

if( $_POST['name2']!= ''){
	die('Spammer!');
}

Save and upload.

Next you need to… Hmm… You don’t need to do anything else ! Now empty your Akismet queue and wait to see if you get any other spam messages ;)

Note that is possible to not catch ALL spams, but those are automated you won’t get it anymore :) Also, when you upgrade wordpress make sure you make those changes again. And finally, BACK UP FIRST!

Tags: ,

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

6 Comments »

  1. great code, i will quit to use akismet plugin on my wordpress blog…

  2. Ionut, te iau pe romana, nu prea stiu sa explic pe engleza. Deci am facut exact cum ai spus tu, acuma deschid wp-comments-post.php dar unde adaug aia cu $post die spamer etc. La sfarsit? Multumesc!

  3. October 24, 2008 Ionut Staicu said:

    Well… Some problems with wp_syntax parse :D Fixed now ;)

  4. Ok, thanks. Work’s now! It’s great, I didn’t got any spam messages!

  5. November 22, 2008 Gmorkster said:

    I would’ve done something like header(”Location: someanimalpornurl.com”); instead of the die() line :) Great idea, congrats!

  6. [...] Mai lipsea să pună un radical şi două variabile şi era sigur că nu mai primeşte spam Am scris acum ceva timp un tutorial să-ţi faci blogul spam free. Împreună cu Akismet am scăpat de spam [...]

Leave a comment

Nu completa urmatorul câmp!