Wordpress Technology

Wordpress Tips, Tutorials, Hacks

Eliminate Comment Spam

Every blogger knows that comment spam is such a pain. Akismet is good solution, but not always. Why not to block spammers, instead of mark them as spam or suspicious as a spam. The code below looks for HTTP reffere in the request header and blocks the comments if the reffer is wrong or not defined.

Insert the following code in functions.php file of current theme:

function check_referrer() {
    if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == "") {
        wp_die( __('Please enable referrers in your browser, or, if you\'re a spammer, get lost!') );
    }
}

add_action('check_comment_flood', 'check_referrer');

Explanation.

The code rejects any comment request posting from a browser that has no reffer. Usually it is a bot. The code checks the for ‘HTTP_REFERRE’. If it’s not defined or incorrect, the execution is stopped with the appropriate message.

Enjoy!


Both comments and pings are currently closed.

© 2009 | Made by Vancouver Web Design | Internet Marketing