Stop Comment Spam

A while ago I posted some PHP code that helps block spam from known IP address by redirecting them to another page.  Check out the original post here: http://cal.freeshell.org/2010/01/spam-prevention/ Since then I have updated the script to include logging functionality.

Or read the rest of this article to for the updated code.

$file_handle = file_get_contents("commentblocklist.txt");

$block = explode("\n", $file_handle);

if (in_array ($_SERVER['REMOTE_ADDR'], $block)) {
$v_ip =$_SERVER['REMOTE_ADDR'];
$v_date = date("l d F H:i:s");

$fp = fopen("ips.txt", "a");
fputs($fp, "IP: $v_ip - DATE: $v_date\n");
fclose($fp);
header("Location: http://google.com");
exit();
}

Or click here to download the complete file as a .txt then rename it with a .php extension and upload it to your server: http://cal.freeshell.org/wp-content/uploads/2010/12/wp-comments-post.txt

This entry was posted in Site Development, Updates and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *