Blacklist that spam, with PHP!(Page 1 out of 2)
Spam is a big problem lately, and if you run any kind of website where a comments system is in place, you�ll probably have to deal with spam sooner or later as well. You might already be receiving several spam comments each day.
To combat this problem you can use several different methods, for example you could setup a moderation system, whereby all comments must be validated before appearing on the website. Or, you could work with a registration system, where all visitors must first register to post comments. But both these solutions make it harder for your visitors to post comments. Definitely not a good thing.
Another option would be a blacklist. The goal of spam is usually to increase the PageRank of certain websites (usually porn websites), so it gets a higher ranking in Google and other search engines. If you can prevent spam, that contains these URLs, from ever being posted, then the spammers no longer have a need to spam your websites.
Implementing a blacklist is relatively simple using some easy PHP. In this tutorial I will show you how to validate a message against a blacklist. I�m not including the comment form or any other form validation. I�m only going to show how to create a blacklist system, in a few easy steps.
The blacklist format
The blacklist we will be using has a specific format, already in use by other blacklist system, e.g. MT-Blacklist, a blacklist system for MovableType. Basically, we will put a separate blacklist entry on each line. Lines starting with a # or blank lines are to be ignored as those are comments or blank. To make our blacklist system even more powerful, it will also support regular expressions so we can match thousands of domains with one rule. For a very good begin to your blacklist, you might want to download Simon Willison�s Blacklist.