Prevent spam in your PHP site with akismet

I’m having some problems with spam in classifieds Barcelona (works with OC), I want to keep the site as clean from spam as possible, but is not easy.

The spammers use people to submit new items, since you need to pass first a captcha and later confirm with email…but that’s not enough and I’m tired of deleting any more spam or advertisements that are not from barcelona.

What I thought is to use akismet, since in WP work pretty good.

I found this php 5 class (download) from achingbrain.net to use the akismet service with php in a really easy way.

But also what I did is to make it even easier for me, because I need to use it in many places I did this small function that only returns if is spam or not:

//Akismet spam preventing you need http://wordpress.com/api-keys/
define('AKISMET','your_api_here');//Akismet.com api key
 
function isSpam($name,$email,$comment){//return if something is spam or not using akismet
	if (AKISMET!=""){
		$akismet = new Akismet(SITE_URL ,AKISMET);//change this! or use defines with that name!
		$akismet->setCommentAuthor($name);
		$akismet->setCommentAuthorEmail($email);
		$akismet->setCommentContent($comment);
		return $akismet->isCommentSpam();
	}
	else return false;//we return is not spam since we don't have the api :(
}

Usage example for a contact form:

if(!isSpam($_POST["name"],$_POST["email"],$_POST["message"])){//check if is spam!
  echo "no spam! great!"			
}//end akismet
else echo "Ups!Spam?";

Die SPAM!!

BTW, this will be in the next release of OC, is already implemented in all forms.

Related Posts Related Websites
Help sharing and Flatter me ;)

Share

4 Comments

  1. andy says:

    hello, it is a great script thank you. i´m testing it now. but can you write under installation instruction how to upgrade from 1.3/ 1.4? i ca´t find this information. thank you

  2. Chema says:

    This is not yet in OC. It will be released in next 1.4.2.

    About 1.3 to 1.4 …. uff long time a go.. :S xD

    My recommendation is:

    Make a backup of files and db.

    Then upload all the new files to your server and open config.php and paste the old config.php, but be aware of new thing that can be in config.php.

    regards

  3. Daniel Remeseiro says:

    you could use the Zend Akismet Class also:
    http://zendframework.com/manual/en/zend.service.akismet.html

    i did not tried Mollom but looks very efective: http://mollom.com/download

  4. Chema says:

    I will check mollom.com I need something better than akismet…is not working really good :S

Leave a Reply

Follow me