September 23, 201411 yr I had built this spam class for my blogging software but it can easily be modified by you to work on any site so I'm just going to post it as is. So far this class as prevented 248 spam comments from getting through on my blog software so it is pretty effective and can be added onto. /** * XSpam is a custom spam library we built to help prevent comment spam on our blog software * this class may however be modified for use with other websites as well that does not use SimpleBlog * @package SimpleBlog v1.2 * @subpackage XSpam */ if(!defined('IN_BLOG')) { exit; } class XSpam{ public $arg_spam_filter = FALSE;//Aggressive spam filter public $disallow_links = TRUE;//Mark anyone who trys to post a link as a spammer public $use_word_list = TRUE;//Use the blocked word list to check against public $spamtrap_name = "xRobot";//Spam trap name //PRIVATE PROPERTIES private $_word_blocked = FALSE; //Common spam words private $block = array( "Acne", "Adipex", "Adult", "Advertisement", "Advertising", "Advicer", "Allergies", "Amazing new discovery", "Ambien", "As seen on tv", "Asthma", "Auto loan", "Auto loans", "Affordable", "Bargain", "Beneficiary", "Best price", "Big bucks", "Cash", "Cash bonus", "Cashcashcash", "Cents on the dollar", "Cheap Check", "Claims", "Collect", "Compare rates", "Cost", "Credit", "Credit bureaus", "Discount", "F r e e", "Fast cash", "For just XXX", "Accept Credit Cards", "Cards accepted", "Check or money order", "Credit card offers", "Explode your business", "Full refund", "Investment decision", "No credit check", "No hidden Costs", "No investment", "Requires initial investment", "Sent in compliance", "Stock alert", "Stock disclaimer statement", "Stock pick", "Sale", "Save", "Scratch and win", "Scratch off", "Scratch-off", "Searching for you", "Sell now", "Sexual health", "Sign up", "Sign up now", "Signup", "Sleeping disorders", "Slot-machine", "Soma", "Stock quotes", "Stop paying", "Substantial income", "Super deal", "Super deals" ); /** *is_spam() *Checks our spammer database table to check if a person is inside the database and *has been marked as a spammer *@[member="param"] string $comment,$email,$ip *@return bool TRUE/FALSE */ public function is_spam($comment,$email,$ip){ //Block the word if word or phrase is inside our blocked array if($this->is_spammer_word($comment) === TRUE && $this->use_word_list === TRUE){ $this->_word_blocked = TRUE; } //Check if comment has link $hasLink = strpos($comment, 'http') !== false || strpos($comment, 'www.') !== false || strpos($comment, '.com') !== false; /** * Check our filtered spam table */ $spam_query = sb_mysql()->SB_query("SELECT * FROM `simpleblog_filtered_spam` WHERE `ip_address` = '$ip' OR `ip_address` = '$ip' AND `email` = '$email' "); /** * Do the checking to see if any of our fields match the spam words * if they do the check fails if not we move on */ if(sb_mysql()->SB_num_rows($spam_query) > 0 || $this->is_spam_trap_tripped() === TRUE || $this->_word_blocked === TRUE || $this->disallow_links === TRUE && $hasLink === TRUE && $this->arg_spam_filter === TRUE ){ return TRUE; }else{ return FALSE; } } /** *is_spam_trap_tripped() *Checks spam trap to see if we have caught any pesky spammers */ public function is_spam_trap_tripped(){ if(!empty($_POST[$this->spamtrap_name])){ return TRUE; }else{ return FALSE; } } /** *is_spammer_word() *Checks if a word from a string is inside our block array, *if it is we return TRUE otherwise return FALSE *@[member="param"] string $str */ public function is_spammer_word($str){ $black_list = "/(".implode("|",$this->block).")/i"; if(preg_match($black_list,$str) ){ return TRUE; }else{ return FALSE; } } } Class Usage <?php $XSpam = new XSpam; if($XSpam->is_spam($comment,$email,$ip) === TRUE){ //Mark as spam }else{ //Proccess Form Data } Edited September 23, 201411 yr by webdesigner93
September 23, 201411 yr Nice, I remember you said you were building a CMS/blogging software. Did you post a link or you're still working on it?
September 23, 201411 yr Author Nice, I remember you said you were building a CMS/blogging software. Did you post a link or you're still working on it? It's been in development for over 2 years I haven't fully made it public due to having quite a few bugs in the software at the beginning. But I just finished v1.2 and it will be public for download soon. But here is a few screenshots I won't show to much Edited September 23, 201411 yr by webdesigner93
September 23, 201411 yr Thanks for sharring your work (again) webdesigner93. And thanks for providing helpfull comments with your code
Create an account or sign in to comment