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

is a designer/developer who makes stuff for screens of all shapes and sizes. He currently works at Edvisors, Inc. where he creates screen-based experiences for used by millions of college students every year.

Wanna Talk?

Contact Me