Many wordpress spam comments are generated by bots calling wp_comments.php directly. Therefore, we can add a filter in WordPress functions.php template to avoid spam comments by checking the page referer.
function check_referrer_comment() {
if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') {
wp_die(__('Please do not access this file directly.'));
}
}
add_action('check_comment_flood', 'check_referrer_comment');
If the server variable HTTP_REFERER is not set or empty, then the page simply dies before any malicious comments are processed. However, some clever bots might still be able to alter/forge the value, but this simple method should filter most of the spam comments.
–EOF (The Ultimate Computing & Technology Blog) —
151 words
Last Post:
How to Find Maximum Product of Word Lengths? Next Post:
The Weird Thing about Javascript - Part I
Disable Spam Comments in WordPress by Checking Referer
Many wordpress spam comments are generated by bots calling wp_comments.php directly. Therefore, we can add a filter in WordPress functions.php template to avoid spam comments by checking the page referer.
function check_referrer_comment() { if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') { wp_die(__('Please do not access this file directly.')); } } add_action('check_comment_flood', 'check_referrer_comment');If the server variable HTTP_REFERER is not set or empty, then the page simply dies before any malicious comments are processed. However, some clever bots might still be able to alter/forge the value, but this simple method should filter most of the spam comments.
–EOF (The Ultimate Computing & Technology Blog) —
151 wordsLast Post: How to Find Maximum Product of Word Lengths?
Next Post: The Weird Thing about Javascript - Part I
Related posts: