0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Reduce Comment Spam by Blocking No-Referrer Requests

As explained in my article, denying access to no-referrer requests, you can greatly reduce the number of spam comments by eliminating all direct requests for your blog’s comments-post.phpfile. This will block automated spam scripts from bypassing your comments form by hitting the comment processing script directly. Here are two ways to block no-referrer comment requests, one uses HTAccess and the other uses PHP. Here is the HTAccess method:

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

Place that code in your site’s root HTAccess file and edit the “domain.tld” to match your own domain. Once in place, this code will redirect any request for your blog’s comments-post.php file that didn’t originate from your site back to the URL from whence it came.

This may also be accomplished via PHP. Place the following function in your theme’s functions.php file:

function check_referrer() {
	if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') {
		wp_die(__('Please do not access this file directly.'));
	}
}
add_action('check_comment_flood', 'check_referrer');

Source: Perishable Press




0