$val) {//for each item of input if (is_array ($val)) $val = join (" / ", $val); //for array inputs $val = trim (strtolower ($val)); //make it lower case if (strlen ($val) > 5) {if (!isset ($repeats[$val])) $repeats[$val] = 0; $repeats[$val]++;} //6) if input is repeated foreach ($bad as $s) if (strpos ($val, $s) !== false) $errors .= ", $key contains $s"; //3) contains bad stuff if (preg_match ("/<\s*>|\[url/i", $val)) $errors .= ", $key contains invalid characters"; //these often appear in SPAM $maxlinks = preg_match ('/' . $haslinks . '$/i', $key) ? 1 : 0; //how many links can these fields include if (preg_match_all ("/ $maxlinks) $errors .= ", $key contains links"; //4) check links if (preg_match ('/' . $notrand . '$/i', $key) && preg_match ('/[bcdfghjklmnpqrstvwxz]{7,}/i', $val)) $errors .= ", $key contains random characters"; //5) check for random characters //6) Check the domains against known lists (from http://weblog.sinteur.com/DNS-anti-spam.phps) if ($checklists && preg_match_all ("/(www.)([^\/\"<\s]*)/im", $val, $m)) { //it contains website addresses foreach ($m[2] as $domain) if (strlen ($domain) > 3) { $domain .= ".sc.surbl.org."; if (gethostbyname ($domain) != $domain) $errors .= ", $domain is a suspected SPAM URL"; } } } //7) check for repeats foreach ($repeats as $string=>$num) if ($num>3) $errors .= ", '$string' is repeated $num times"; //Now output a forbidden message if ($errors && $forbid) { //forbid them echo "

Suspected SPAM

Sorry, but your submission has been rejected because it looks "; echo "a little bit like SPAM. Please return and try again. "; echo "The following errors were reported: " . substr ($errors, 2) . "."; echo "

\n"; exit; } //Return if this is suspected SPAM or not return $errors ? true : false; } ?>