logo spacer

Design Resources: PHP AntiSpam Script

mascot
spacer icon menu spacer
spacer
You are here: bulletHome > Design Resources > PHP AntiSpam Script



Website Design Logo

Colour Key:

  • || Page Links
  • a. Site Menu
  • || Emphasis Only

 


bulletAntispam Script for Website Contact Forms

Script kiddies seem to be rampant this year. Two of our clients' sites have been hit with the same off-the-shelf spam script in as many months. Our IP blocking software works well for known spammers, but these script kiddies pop-up out of the woodwork everywhere. So after rejecting php.net's offerings for antispam coding strategies, we decided to come up with a simple, generic script that can just be included with any mail processing script.

We're targeting the spammer who will attempt to inject their own email header information into one or more form fields. This way they can Cc and Bcc to as many addresses they want to and customize other header info.

How this script works is firstly by concatenating all POST values into one long string, then search the string against an array of terms and phrases ('needles') used by spammers to modify headers. If a match is found, the script exits with a blunt error message:

<?php
// spammer detection script

// string needle array assignments

$needles[] = 'MIME-Version:';
$needles[] = 'Content-Type';
$needles[] = 'Content-Transfer-Encoding';
$needles[] = 'Subject:';

// concatenate POST vars to $strHaystack

$strHaystack = '';

$limit = count($_POST);

foreach ($_POST as $index => $value){

$strHaystack .= $value;

}

// do search

$limit = count($needles);

for ($i=0; $i < $limit; $i++){

if(eregi($needles[$i],$strHaystack)){

die('Go spam someone else\'s server!');

}
}

?>

Copy and paste the code into a new php file and include it with your mail processing script. For added control over when the anti-spam script runs, paste the code into the conditional statement which executes when the email form is submitted.

 

 

 

spacer spacer
Copyright © 2005 v2Media All Rights Reserved.
By using this Website, you agree with our Terms and Conditions.

www.v2media.biz contact details;
phone: +61 7 3420 5492 mobile: +61 0407 133805 email: sales@v2media.biz