protected function isSpamAttempt()
    {

        /*
        * loop through all files in the tmp directory and
        * delete garbage files
        */
        $dir = $this->tmp_path;
        $numPrefixChars = strlen($this->file_prefix);
        $files = scandir($dir);
        foreach ($files as $file) {
            if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                if (substr($file, 0, $numPrefixChars) == $this->file_prefix) {
                    $lastModified = filemtime($dir . DIRECTORY_SEPARATOR . $file);
                    if ((time() - $lastModified) > 3600) {
                        unlink($dir . DIRECTORY_SEPARATOR . $file);
                    }
                }
            }
        }

        /*
        * end deleting garbage files
        */
        $remoteAddr = $this->ip;
        $userAgent  = $_SERVER['HTTP_USER_AGENT'];
        $filename   = $this->file_prefix . md5($remoteAddr.$userAgent) . '.tmp';
        $file       = $dir . DIRECTORY_SEPARATOR . $filename;

        if (!file_exists($file)) {
            $handle = fopen($file, 'w');
            fwrite($handle, time());
            fclose($handle);

            return false;
        }

        $lastAttack = file_get_contents($file);
        $difference = time() - $lastAttack;
        if ($difference > $this->allowed_rate) {
            unlink($file);
        } else {
            return true;
        }

        return false;
    }
protected function isSpamAttempt()
    {

        /*
        * loop through all files in the tmp directory and
        * delete garbage files
        */
        $dir = $this->tmp_path;
        $numPrefixChars = strlen($this->file_prefix);
        $files = scandir($dir);
        foreach ($files as $file) {
            if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
                if (substr($file, 0, $numPrefixChars) == $this->file_prefix) {
                    $lastModified = filemtime($dir . DIRECTORY_SEPARATOR . $file);
                    if ((time() - $lastModified) > 3600) {
                        unlink($dir . DIRECTORY_SEPARATOR . $file);
                    }
                }
            }
        }

        /*
        * end deleting garbage files
        */
        $remoteAddr = $this->ip;
        $userAgent  = $_SERVER['HTTP_USER_AGENT'];
        $filename   = $this->file_prefix . md5($remoteAddr.$userAgent) . '.tmp';
        $file       = $dir . DIRECTORY_SEPARATOR . $filename;

        if (!file_exists($file)) {
            $handle = fopen($file, 'w');
            fwrite($handle, time());
            fclose($handle);

            return false;
        }

        $lastAttack = file_get_contents($file);
        $difference = time() - $lastAttack;
        if ($difference > $this->allowed_rate) {
            unlink($file);
        } else {
            return true;
        }

        return false;
    }
protected function isSpamAttempt ( ) { /*
        * loop through all files in the tmp directory and
        * delete garbage files
        */ $ dir = $ this -> tmp_path ; $ numPrefixChars = strlen ( $ this -> file_prefix ) ; $ files = scandir ( $ dir ) ; foreach ( $ files as $ file ) { if ( is_file ( $ dir . DIRECTORY_SEPARATOR . $ file ) ) { if ( substr ( $ file , 0 , $ numPrefixChars ) == $ this -> file_prefix ) { $ lastModified = filemtime ( $ dir . DIRECTORY_SEPARATOR . $ file ) ; if ( ( time ( ) - $ lastModified ) > 3600 ) { unlink ( $ dir . DIRECTORY_SEPARATOR . $ file ) ; } } } } /*
        * end deleting garbage files
        */ $ remoteAddr = $ this -> ip ; $ userAgent = $ _SERVER [ 'HTTP_USER_AGENT' ] ; $ filename = $ this -> file_prefix . md5 ( $ remoteAddr . $ userAgent ) . '.tmp' ; $ file = $ dir . DIRECTORY_SEPARATOR . $ filename ; if ( ! file_exists ( $ file ) ) { $ handle = fopen ( $ file , 'w' ) ; fwrite ( $ handle , time ( ) ) ; fclose ( $ handle ) ; return false ; } $ lastAttack = file_get_contents ( $ file ) ; $ difference = time ( ) - $ lastAttack ; if ( $ difference > $ this -> allowed_rate ) { unlink ( $ file ) ; } else { return true ; } return false ; }
Detects spam attempts

To avoid mail spam through this logging class this function is used
to detect such attempts based on the alert frequency.

@return boolean
Detects spam attempts