I'm always the first to admit when I make a mistake. And hoo boy, did I ever make one here. I recently created a website for a friend using Drupal. This friend didn't use the site for a few weeks, and when she went to make a blog posting, we discovered that the site had been overrun with comments advertising Viagra, Paxil, Tamiful, "h5n1" masks, and kamagra jelly gel (whatever that is). Overrun to the tune of 48,495 comments in the span of 1 month, to be exact. Yikes!
Rather than have her website become a perpetual illicit online drug store, I quickly fixed my mistakes to deter the comment spammers. Since I feel strongly that one should always learn from his/her mistakes, here's what I did to stop the flood of comment spam so you don't have to learn the hard way like I did.
The biggest mistake I made with this site was to allow anonymous users the ability to post comments without moderation. The first step I took in fixing this problem was to take away that privilege. Anonymous commentators will still be able to leave comments, but you will have to approve them before they can be posted to the website (see our earlier post on how to be notified when new comments are posted).
Do this by going to Administer > User Management > Access Control. Scroll down to the Comment Module, and uncheck the box next to "post comments without approval." Scroll down to the bottom of the page, and click Save Permissions.

This is the meat-and-potatoes of this fix: you'll want to make it as hard as possible for bot or other automated scripts from posting comments. The best way I've found of doing this is requiring a CAPTCHA before visitors can submit their comment. Here's how to enable CAPTCHAs with Drupal:





Warning: the information posted in this step has the potential to completely hose up your website. Please backup your database before trying and proceed with caution!
Now that you've prevented new comment spam from being posted, you'll want to remove the existing spam messages. Log into your website's web control panel, and get to the MySQL admin section (my host uses phpMyAdmin). Find the table named "comments", and browse it. Do you have about a bajillion spam comment records? Good, then you're in the right place.
We're going to run a SQL query to delete all those comment records from the database, so this means you will lose your non-spam comments too. I'd suggest wiping the comment table clean then manually inputting any good comments you have.
delete from comments where status = '0'

Click the Go button on the lower right of the screen. The page will refresh, and you'll get a message saying how many rows were deleted. All my comments were unpublished, so none were deleted.
![]()
delete from comments where status = '1'
This time there should be significantly more records deleted.
![]()
Read more: Web Development, Tutorials, Drupal
Post new comment