helgesverre/spamprotection

用于联系表单和评论字段的垃圾邮件保护类,使用StopForumSpam API。

1.0.1 2015-10-23 00:00 UTC

This package is auto-updated.

Last update: 2024-08-27 01:09:15 UTC


README

Latest Version on Packagist Software License Total Downloads

PHP 垃圾邮件保护类,用于联系表单和评论字段

使用此类所需的API密钥可以在以下位置获得:http://www.stopforumspam.com/signup

只有在使用submitReport()函数时才需要API密钥。

安装

$ composer require helgesverre/spamprotection

用法

Example.php

<?php
use Helge\SpamProtection\SpamProtection;
use Helge\SpamProtection\Types;

require 'vendor/autoload.php';

$spamProtector = new SpamProtection();


/** 
 * All checks can be called from the check() method, 
 * first param is the type of check, second is the value (ip, email, username)
 */
var_dump($spamProtector->check(Types::EMAIL, "helge.sverre@gmail.com"));
var_dump($spamProtector->check(Types::IP, "8.8.8.8"));
var_dump($spamProtector->check(Types::USERNAME, "helgesverre"));

/**
 * For convenience some wrapper methods are provided, 
 * they simply pass the data long to check()
 */
var_dump($spamProtector->checkEmail("helge.sverre@gmail.com"));
var_dump($spamProtector->checkIP("8.8.8.8"));
var_dump($spamProtector->checkUsername("spammer"));

检查方法返回bool值,其中TRUE表示IP/Email/Username已被标记为垃圾邮件。

如果您想指定一个“阈值”,即需要多少个垃圾邮件报告才能标记某事物为垃圾邮件,可以使用setFrequencyThreshold()方法或指定构造函数中的阈值。

<?php
use Helge\SpamProtection\SpamProtection;
use Helge\SpamProtection\Types;

require 'vendor/autoload.php';

/*
    The following constants are available in the spamprotection class for convenience
    const THRESHOLD_STRICT = 1;
    const THRESHOLD_HIGH = 3;
    const THRESHOLD_MEDIUM = 5;
    const THRESHOLD_LOW = 10;
*/

$spamProtector = new SpamProtection(SpamProtection::THRESHOLD_STRICT);

// or 

$spamProtector = new SpamProtection();
$spamProtector->setFrequencyThreshold(SpamProtection::THRESHOLD_HIGH);

当遇到时,该库还可以将Tor出口节点标记为垃圾邮件。

要启用此功能,请使用setAllowTorNodes($allowTorNodes)将其设置为true或false,或指定为构造函数中的第二个参数。

<?php
use Helge\SpamProtection\SpamProtection;
use Helge\SpamProtection\Types;

require 'vendor/autoload.php';

/*
    The following constants are available in the spamprotection class for convenience
    const TOR_ALLOW = true;
    const TOR_DISALLOW = false;
*/

$spamProtector = new SpamProtection(SpamProtection::THRESHOLD_STRICT, SpamProtection::TOR_DISALLOW);

// or 

$spamProtector = new SpamProtection();
$spamProtector->setAllowTorNodes(false);

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件