Professional Freelance Web Developer
CodeIgniter Activist, Caffeine Junkie

Elliot Haughin

Akismet CodeIgniter Library

Akismet is a remotely hosted spam-busting web service.
If you have a CodeIgniter application that accepts comments from users, Akismet can help you filter out the ’spam’ comments and keep the ‘real’ comments.

Akismet Logo

We can’t stand spam.

Who can? You have better things to do with your life than deal with the underbelly of the internet. Automattic Kismet (Akismet for short) is a collaborative effort to make comment and trackback spam a non-issue and restore innocence to blogging, so you never have to worry about spam again.

To use the library, you’ll need to get an Akismet API Key

Download the library and put it in your application/libraries/ directory, then place code like this in your controller:

$this->load->library('akismet');
 
$comment = array(
'author'	=> $this->input->post('name'),
'email'		=> $this->input->post('email'),
'website'	=> $this->input->post('website'),
'body'		=> $this->input->post('comment')
);
 
$config = array(
'blog_url' => 'http://www.yoursite.com/',
'api_key' => 'yourapikeyhere',
'comment' => $comment
);
 
$this->akismet->init($config);
 
if ( $this->akismet->errors_exist() )
{				
	if ( $this->akismet->is_error('AKISMET_INVALID_KEY') )
	{
	log_error('AKISMET :: Theres a problem with the api key');
	}
	elseif ( $this->akismet->is_error('AKISMET_RESPONSE_FAILED') )
	{
	log_error('AKISMET :: Looks like the servers not responding');
	}
	elseif ( $this->akismet->is_error('AKISMET_SERVER_NOT_FOUND') )
	{
	log_error('AKISMET :: Wheres the server gone?');
	}
 
	// If the server is down, we have to post the comment :(
	$this->_post_comment($comment);
	$this->load->view('thankyou');
}
else
{
	if ( $this->akismet->is_spam() )
	{
		$this->load->view('spam');
	}
	else
	{
		$this->_post_comment($comment);
		$this->load->view('thankyou');
	}
}

Download Akismet CodeIgniter Library

Version: 1.0

Boring Stuff

Design © copyright Elliot Haughin 2009

Content published here are copyright their respective owners.

You cannot copy content from this site, either in English or translated to another language.

Keep Subscribed

Theres lots of ways for you to keep up with me on the web.

Please Note

Information given out on this blog should only be used as a guideline. I hold no liability for any code I write.

Always consult a professional before acting on this guidance.