Mobile app version of vmapp.org
Login or Join
Jessie594

: PHP software to detect spam? Possible Duplicate: How can I prevent spam on sites which I control? I'm looking for something like spam-assassin or similar, except it only focuses

@Jessie594

Posted in: #Comments #Php #Spam

Possible Duplicate:
How can I prevent spam on sites which I control?




I'm looking for something like spam-assassin or similar, except it only focuses on the message rather than inspecting an entire email header.

It doesn't even need to be really fancy, just do the classification of messages. In theory we could provide meta-data such as IP.

I'm doing this because I want an feedback forum without authentication or recaptcha or having to put every email in the "pending" bin before it's published.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie594

2 Comments

Sorted by latest first Latest Oldest Best

 

@Debbie626

You can create your own spam filter classes and use it.

I use following class to detect spam on comments:

class CommonFunctions{

private $spam_array = array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
'.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
'.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
'.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
'.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
'.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
'.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
'.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
'.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
'.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
'.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
'.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw');







/*
*find whether a string contains html
*@param string
*@return boolean
*/
public function containHtml($data){

if(strlen($data) != strlen(strip_tags($data))){
return true;
}

return false;

}
//function end

public function isOK($data){
if(strlen(trim($data))>0){
if(!$this->containHtml($data)){
if(!$this->containSpam($data)){
return true;
}
}
}
return false;
}
/*
*find whether a string contains spam
*@param string
*@return boolean
*/
public function containSpam($data){
$data=strtolower($data);
foreach($this->spam_array as $spam_word){
//echo "<br>Data is $data Word is $spam_word ".stripos($data,$spam_word)."<br/>";

if($this->cusFnmatch("*$spam_word*",$data)){
return true;
}

}

return false;

}
//function end


function cusFnmatch($needl,$check_string){

if (!function_exists('fnmatch')) {
define('FNM_PATHNAME', 1);
define('FNM_NOESCAPE', 2);
define('FNM_PERIOD', 4);
define('FNM_CASEFOLD', 16);

function fnmatch($pattern, $string, $flags = 0) {
return pcre_fnmatch($pattern, $string, $flags);
}
}

if(!function_exists('pcre_fnmatch')){

function pcre_fnmatch($pattern, $string, $flags = 0) {
$modifiers = null;
$transforms = array(
'*' => '.*',
'?' => '.',
'[!' => '[^',
'[' => '[',
']' => ']',
'.' => '.',
'' => '\'
);

// Forward slash in string must be in pattern:
if ($flags & FNM_PATHNAME) {
$transforms['*'] = '[^/]*';
}

// Back slash should not be escaped:
if ($flags & FNM_NOESCAPE) {
unset($transforms['']);
}

// Perform case insensitive match:
if ($flags & FNM_CASEFOLD) {
$modifiers .= 'i';
}

// Period at start must be the same as pattern:
if ($flags & FNM_PERIOD) {
if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) return false;
}

$pattern = '#^'
. strtr(preg_quote($pattern, '#'), $transforms)
. '$#'
. $modifiers;

return (boolean)preg_match($pattern, $string);
}
}
return fnmatch($needl,$check_string);
}

}


and i'll check for spam like this,

include_once "class.commonfunctions.php";

$cmn=new CommonFunctions();
if(!$cmn->isOK($comment))
{
return false;
}
else{

//proceed with insert

}

10% popularity Vote Up Vote Down


 

@Sarah324

Have you considered Akismet? It's excellent at catching spam.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme