aii-anti-spam-behavior This exension can be used in models, e.g. comment models, to avoid spamming

  1. Requirements
  2. Usage
  3. Resources

This behavior is designed to use as anti-spam solution e.g. for comments model. The basis of this solution is to use hidden fields in form and check if they are empty during validation. This is because most of spam-bots fill all fields in form. Real users doesn't :) Second anti-spam solution is checking how long form is filled by submitter. Robots fills form really quick, while user need for that at least 1-2 seconds. Measuring time between creating model and saving it gives us answer if we are dealing with form filled by reals user or spam-bot.


Yii 1.1 or above


Configure behavior in model. Note that setting errorMessage is useful, when you want to inform user, that he was classified as spammer.

public function  behaviors()
        return CMap::mergeArray(parent::behaviors(), array(
                'scenario'=>'insert', //model scenario in which our behavior will be used
                        'field'=>'email',//field or comma separated field names to be empty hidden and empty during submitting form
                        'default'=>'', //default value if needed
                        'errorMessage'=>'Your message where classified as spam. Please contact admin or owner of this site, if you think this was done by mistake.'
                        'min'=>2,//min. time in seconds between model creation and saving it
                        'field'=>'email',//field where error message should be displayed 
                        'errorMessage'=>'Go away spammer!' //error message


2 0
Yii Version: 1.1
License: BSD-2-Clause
Category: Security
Developed by: aztech
Created on: Nov 15, 2010
Last updated: 13 years ago


show all

Related Extensions