CodeIgniter Anti-Spam Snippet

Here at the studio, we focus on using the wonderful open source CodeIgniter framework to power things behind the scenes on most of the sites we build.

I had to quickly whip up a new callback function for a contact form that was being spammed.

function no_spam($str)
{
    if (strpos($str, '[url=') === FALSE)
    {
        return TRUE; 
    }
    else
    {
        $this->form_validation->set_message('no_spam', 'The %s field no like spam!');
        return FALSE;
    }
}

A pretty easy way to deter comment form spam from entering your inbox.

Feel free to use this function in any CodeIgniter controller that has a <textarea> form fill-in field.


About Joseph R. B. Taylor

Joseph R. B. Taylor is a humble designer/developer who makes stuff for screens of all shapes and sizes. He is currently the lead UI/UX Architect at MScience, LLC, where he works to create simple experiences on top of large rich datasets for their customers and clients.