Several methods are recommended to defend against wordpress spam comments

Source: Internet
Author: User
Tags comments php file regular expression

Last week, my blog suddenly failed to access the server. I asked the server provider to say "my traffic wife", which affected the normal operation of the server. I hate it. Download and take a local view, more than two thousand spam comments. I realized that the server load caused by spam comments is too high. Then I had to temporarily close the comment. Then, the various search solutions on the website are summarized as follows: spam comments cannot be cleared at the bottom of the test, but they can only be cleared manually if they are done well. But it does not cause high server load to fail.

I used two methods. Here I will share with you, because sooner or later you will use them. Haha !!

1. Block all comments in English (excluding Chinese characters.

You only need to modify the functions. php under the topic directory you are currently using and will not be affected by the WordPress upgrade. Specific modification: open functions. php under the currently used topic directory, and add the following code at the end. This can block a lot of spam comments in English only. Spam comments account for a large proportion in Chinese and English.

The code is as follows: Copy code

Function scp_comment_post ($ incoming_comment ){
$ Pattern = '/[1-?] /U ';

// Disable all comments in English
If (! Preg_match ($ pattern, $ incoming_comment ['Comment _ content']) {
Wp_die ("You shocould type some Chinese word (like" Hello ") in your comment to pass the spam-check, thanks for your patience! Your comment must contain Chinese characters! ");
    }
Return ($ incoming_comment );
}
Add_filter ('preprocess _ comment', 'scp _ comment_post ');

2. Modify the wp-comments-post.php file name so that the robot could not find the comment entry. (For more information, see Weiyan Weiyu)

We all know that the vast majority of spam comments are submitted through the wp-comments-post.php under the root directory of the post site, so we can not find the post entry, then it can not send spam comments. For common users, the general solution is:

Rename the wp-comments-post.php under the blog root directory, change anything can, such as no-comments-post.php

Open comments. php in the topic, find the wp-comments-post.php in the code, and change it to no-comments-post.php.

The modified name is the same as the previously modified name. We recommend that you do not set this rule to prevent the spam comment publishing mechanism from upgrading the regular expression matching to guess some similar addresses.

This mainly aims to modify the comment path so that no entry can be found for posting spam comments, thus blocking spam comments. I am still using this method very well. If your WordPress has a lot of spam comments, you may also use this method.

Prevent duplicate spam comments from the same ip address. If spam comments are sent to an ip address, no comments will be submitted within 24 hours.

You need to add the following code to the functions. Php file of your WordPress topic:

The code is as follows: Copy code

// Rectify spam comments
If (! Function_exists ('antispam _ check ')):
Function antispam_check ($ comment ){
Global $ wpdb;
$ Query = $ wpdb-> prepare ('SELECT COUNT (*) AS SPAM_COUNT, MAX (comment_date_gmt) AS LAST_SPAM_DATE FROM '. $ wpdb-> comments. 'Where comment_approved = 'spam' AND comment_author_IP = % s', preg_replace ('/[^ 0-9a-fA-F:.,] /', "", $ _ SERVER ['remote _ ADDR']);
$ Comment_count = $ wpdb-> get_row ($ query, ARRAY_A );
If ($ comment_count ['spam _ count']> = 1 ){
Wp_die. ');
} Elseif ($ comment_count ['spam _ count']> 0 & gmmktime ()-strtotime ($ comment_count ['last _ SPAM_DATE '], gmmktime ()) <24*3600 ){
Wp_die. ');
 }
Return $ comment;
}
Endif;
Add_action ('preprocess _ comment', 'antispam _ check ');

Of course, some friends said that I would also sort out some of the plug-ins below.

1. Akismet

Akismet is a WordPress anti-spam comment plug-in officially recommended by WordPress. It has powerful functions. After activating Akismet, it can automatically block and filter most spam comments, however, Akismet is not enabled or activated by default. Today, we will show new friends how to activate the Akismet anti-spam comment plug-in.

2. Math Comment Spam Protection 3.0 Plug-in

Of course, the comments are all in English. You only need to translate the error into English. After a few days of trial, it really feels good. We recommend that you have a blog friend to try ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.