Two simple ways to make your wordpress blog safe from spam comments without using captcha.

Anyone who runs a blog might have experienced the problem of many spam comments coming to your blog from nowhere.
There are so many bots over www trying to make spam comments in others blog. They do so to promote their link, to make others blog go down or just for fun.

Basically most of such bots does not open your blog pages they just write comment using software and post it by accessing http://yourblog.com/wp-comments-post.php
This problem can be solved by using a captcha plugin for your blog. But captcha gives an extra burden for your blog readers and they don’t like it.
So here is how to stop such comment spam to make your blog secure by smple method.

What we are going to do in following tricks is to disallow to open the file http://yourblog.com/wp-comments-post.php if it is not opened from your blog pages. So that spam bots and software will not be able to access the commenting file.

So two ways to do so are mentioned below:

1> By Editing .htaccess

If you have enough technical skills and have access to files in your server you can use this method. Just edit the .htaccess file located in the directory of your wordpress blog and paste the following code some where inside the text of .htaccess file.


RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Don’t forget to replace yourblog.com with the URl of your blog.

2> By editing functions.php file of your theme.

If you have administration access to your blog you can use this method it is easier and non technical than the first method.
In this method we will edit files of your wordpress theme and put an extra function on it.

Login to your wordpress blog and click on “Editor” Below the “Appearance” Tab at the side of your administrative panel.
Now in the windows that opens search for the file name “Functions.php” And click on it. And paste the following code some where in the text of file. But paste the code before the " ?> " Tag given at the last of the functions.php file.

Code:

function check_referrer() {
if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == “”) {
wp_die( __('Sorry we think that you are a spammer. So we blocked the commenting option for you temporarily. If you are not a spammer try commenting again and if the problem continues contact us. ') );
}
}

add_action('check_comment_flood', 'check_referrer');



Popular Searches:



 

About the author

More posts by admin | Visit the site of admin

 

4 Comments

  1. Pritush says:

    can you give a short explanation on how this works ?
    and if some one come to the post from other site will comment get marked as spam.

    • subash says:

      What I mean is to make comments when you click post comment a file “http://yourblog.com/wp-comments-post.php” Is opened. So the codes above will not allow to open the commenting file if the visitor haven’t opened your blog posts but only trying to open the commenting file.

  2. an essay says:

    Very nice Blog, I will tell my friends about it.

    Thanks

  3. May you use nofollow backlinks this help.

Leave a Comment

 

You must be logged in to post a comment.