Comment spam isn't a security risk, but a boring reality for every blogger. Sure, the Akismet plugin is very good at avoiding spam, but what about preventing spam instead of simply putting it in a specific queue?
In this recipe, I'm going to show you how to block comment postings to no referrer requests. This hack consists of looking up the referrer (the page from where the comment posting request comes) and blocking it, if the request doesn't come from your blog.
Most spammers don't even go to your blog to post their spam comments, they use a dedicated script or software to do it. As the request comes from a specific script instead of your blog, the following codes will block the spam comments.