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.
Requirements ¶
Yii 1.1 or above
Usage ¶
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(
'antiSpam'=>array(
'class'=>'ext.AiiAntiSpamBehavior',
'scenario'=>'insert', //model scenario in which our behavior will be used
'emptyFieldsConfig'=>array(
array(
'field'=>'email',//field or comma separated field names to be empty hidden and empty during submitting form
'default'=>'no-spam@spam.com', //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.'
)
),
'submitTimeConfig'=>array(
'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
),
)
));
}
Another idea
Nice one. I have another idea that is not so easy to implement but that should be very efficient.
There are, of course, some cons:
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.