public static function tooMany($userId)
    {
        $sessionKey = 'messages.' . $userId;
        if (Yii::$app->session->has($sessionKey)) {
            $sentAlready = explode('|', Yii::$app->session->get($sessionKey));
            $validated = [];
            foreach ($sentAlready as $t) {
                if (preg_match('/^[0-9]+$/', $t)) {
                    if ($t > time() - self::SPAM_WAIT * 60) {
                        $validated[] = $t;
                    }
                }
            }
            Yii::$app->session->set($sessionKey, implode('|', $validated));
            if (count($validated) >= self::SPAM_MESSAGES) {
                return true;
            }
        }
        return false;
    }
public static function tooMany($userId)
    {
        $sessionKey = 'messages.' . $userId;
        if (Yii::$app->session->has($sessionKey)) {
            $sentAlready = explode('|', Yii::$app->session->get($sessionKey));
            $validated = [];
            foreach ($sentAlready as $t) {
                if (preg_match('/^[0-9]+$/', $t)) {
                    if ($t > time() - self::SPAM_WAIT * 60) {
                        $validated[] = $t;
                    }
                }
            }
            Yii::$app->session->set($sessionKey, implode('|', $validated));
            if (count($validated) >= self::SPAM_MESSAGES) {
                return true;
            }
        }
        return false;
    }
public static function tooMany ( $ userId ) { $ sessionKey = 'messages.' . $ userId ; if ( Yii :: $ app -> session -> has ( $ sessionKey ) ) { $ sentAlready = explode ( '|' , Yii :: $ app -> session -> get ( $ sessionKey ) ) ; $ validated = [ ] ; foreach ( $ sentAlready as $ t ) { if ( preg_match ( '/^[0-9]+$/' , $ t ) ) { if ( $ t > time ( ) - self :: SPAM_WAIT * 60 ) { $ validated [ ] = $ t ; } } } Yii :: $ app -> session -> set ( $ sessionKey , implode ( '|' , $ validated ) ) ; if ( count ( $ validated ) >= self :: SPAM_MESSAGES ) { return true ; } } return false ; }
Checks if user sent already more than SPAM_MESSAGES in last SPAM_WAIT
minutes.
@param int $userId
@return bool
Checks if user sent already more than SPAM_MESSAGES in last SPAM_WAIT minutes .