PHPackages                             mirko-pagliai/cakephp-stop-spam - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mirko-pagliai/cakephp-stop-spam

ActiveCakephp-plugin[Validation &amp; Sanitization](/categories/validation)

mirko-pagliai/cakephp-stop-spam
===============================

A CakePHP plugin that allows you to check if a username, email address or ip address has been reported as a spammer

1.2.1(2y ago)318.7k1[1 PRs](https://github.com/mirko-pagliai/cakephp-stop-spam/pulls)MITPHPPHP &gt;=8.1

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mirko-pagliai/cakephp-stop-spam)[ Packagist](https://packagist.org/packages/mirko-pagliai/cakephp-stop-spam)[ Docs](https://github.com/mirko-pagliai/cakephp-stop-spam)[ RSS](/packages/mirko-pagliai-cakephp-stop-spam/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (6)Versions (21)Used By (0)

cakephp-stop-spam
=================

[](#cakephp-stop-spam)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)[![CI](https://github.com/mirko-pagliai/cakephp-stop-spam/actions/workflows/ci.yml/badge.svg)](https://github.com/mirko-pagliai/cakephp-stop-spam/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/5498c7846ea0fa183a4a464386b36b6097b8f5a96f310f2099d5f5c4ffbb3c72/68747470733a2f2f636f6465636f762e696f2f67682f6d69726b6f2d7061676c6961692f63616b657068702d73746f702d7370616d2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mirko-pagliai/cakephp-stop-spam)[![Codacy Badge](https://camo.githubusercontent.com/d50b01e637aae8b359dcc4198db9f9e7f01c8a1fc682c05caeb43cc2b6d66f7a/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3130616332366637303964393461616138653662626235643037643762303530)](https://www.codacy.com/gh/mirko-pagliai/cakephp-stop-spam/dashboard?utm_source=github.com&utm_medium=referral&utm_content=mirko-pagliai/cakephp-stop-spam&utm_campaign=Badge_Grade)[![CodeFactor](https://camo.githubusercontent.com/8b531f7f8688f417810427bf192ca2de2a884a75c54b8adc028e26afba269b7a/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6d69726b6f2d7061676c6961692f63616b657068702d73746f702d7370616d2f6261646765)](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-stop-spam)

*cakephp-stop-spam* is a CakePHP plugin that allows you to check if a username, email address or ip address has been reported as a spammer using services and APIs offered by [stopforumspam.org](https://stopforumspam.com).

Did you like this plugin? Its development requires a lot of time for me. Please consider the possibility of making [a donation](//paypal.me/mirkopagliai): even a coffee is enough! Thank you.

[![Make a donation](https://camo.githubusercontent.com/d9f2015fc776952b7d14005e3f0e18099924deeb096bffd93869762ebecde952/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f7765627374617469632f6d6b74672f6c6f676f2d63656e7465722f6c6f676f5f70617970616c5f63617274652e6a7067)](//paypal.me/mirkopagliai)

---

- [Installation](#installation)
    - [Installation on older CakePHP and PHP versions](#installation-on-older-cakephp-and-php-versions)
        - [For PHP 7.2 and CakePHP 4 or later](#for-php-72-and-cakephp-4-or-later)
        - [For PHP 5.6 and CakePHP 3 or later](#for-php-56-and-cakephp-3-or-later)
- [How to use](#how-to-use)
    - [The Request detector](#the-request-detector)
    - [How to create a validation rule](#how-to-create-a-validation-rule)
    - [How to configure the cache](#how-to-configure-the-cache)
- [Versioning](#versioning)

Installation
------------

[](#installation)

You can install the plugin via composer:

```
$ composer require --prefer-dist mirko-pagliai/cakephp-stop-spam
```

Then you have to load the plugin. For more information on how to load the plugin, please refer to the [Cookbook](//book.cakephp.org/4.0/en/plugins.html#loading-a-plugin).

Simply, you can execute the shell command to enable the plugin:

```
bin/cake plugin load StopSpam
```

This would update your application's bootstrap method.

### Installation on older CakePHP and PHP versions

[](#installation-on-older-cakephp-and-php-versions)

Recent packages and the master branch require at least CakePHP 5.0 and PHP 8.1 and the current development of the code is based on these and later versions of CakePHP and PHP. However, there are still some branches compatible with previous versions of CakePHP and PHP.

#### For PHP 7.2 and CakePHP 4 or later

[](#for-php-72-and-cakephp-4-or-later)

The [php7.2](//github.com/mirko-pagliai/cakephp-stop-spam/tree/php7.2) branch requires at least PHP `>=7.2` and CakePHP `^4.0`.

In this case, you can install the package as well:

```
$ composer require --prefer-dist mirko-pagliai/cakephp-stop-spam:dev-php7.2
```

Note that the `php7.2` branch will no longer be updated as of January 7, 2024, except for security patches, and it matches the [1.1.8](//github.com/mirko-pagliai/cakephp-stop-spam/releases/tag/1.1.8) version.

#### For PHP 5.6 and CakePHP 3 or later

[](#for-php-56-and-cakephp-3-or-later)

The [cakephp3](//github.com/mirko-pagliai/cakephp-stop-spam/tree/cakephp3) branch requires at least PHP 5.6 and CakePHP 3.

In this case, you can install the package as well:

```
$ composer require --prefer-dist mirko-pagliai/cakephp-stop-spam:dev-cakephp3
```

Note that the `cakephp3` branch will no longer be updated as of May 7, 2021, except for security patches, and it matches the [1.1.3](//github.com/mirko-pagliai/cakephp-stop-spam/releases/tag/1.1.3) version.

How to use
----------

[](#how-to-use)

After instantiating the class, you can use `email()`, `ip()` and `username()`methods to specify the values to be verified and finally use the `verify()` method to get the result. Example:

```
$SpamDetector = new SpamDetector();
$SpamDetector->email('test@example.com')
    ->ip('8.8.8.8')
    ->username('mirko');
$result = $SpamDetector->verify();
```

The `verify()` method returns `false` if ***certainly at least one of the parameters*** has been reported as a spammer, otherwise returns `true`. In other words, ***the `verify()` method verifies that it is not a spammer***.

If the API returns an error (for example if you specify an invalid ip address, or in any case if you generate a request that cannot be interpreted), an exception will be throwed.

`email()`, `ip()` and `username()` methods are chainable and can be called more than once, or you can pass multiple arguments. Example (the `email()`) method is called multiple times, while the `ip()` method is called with multiple arguments):

```
$SpamDetector = new SpamDetector();
$SpamDetector->email('test@example.com');
$SpamDetector->email('anothermail@example.com');
$SpamDetector->ip('8.8.8.8', '8.8.4.4');
$result = $SpamDetector->verify();
```

### The Request detector

[](#the-request-detector)

The plugin also adds the `is('spammer')` request detector. This detector checks if the user's IP address is reported as spammer. Wherever the server request is accessible, you can use the detector. An example:

```
class PagesController extends AppController
{
    /**
     * A "view" action for PagesController
     */
    public function view()
    {
		$isSpammer = $this->getRequest()->is('spammer');

		if ($isSpammer) {
			throw new InternalErrorException('Ehi, you are a spammer! Get out of my site!');
		}

		// ...
	}
}
```

The detector checks if the IP address of the user client is reported as a spammer. This happens as described above. If the IP address is not reported, the detector uses the session to store the control result.

This is very convenient and fast. It avoids repeating the code and also, using the session to memorize the result, it does not even use the cache.

### How to create a validation rule

[](#how-to-create-a-validation-rule)

The plugin can also be used as a validation rule. Just an example:

```
class ContactUsForm extends Form
{
    protected function _buildValidator(Validator $validator)
    {
	    //some rules for my form...

        $validator->add('email', [
            'notSpammer' => [
                'message' => 'Sorry, this email address has been reported as a spammer!',
                'rule' => function ($value, $context) {
                    return (new SpamDetector())->email($value)->verify();
                },
            ],
        ]);

        return $validator;
    }
}
```

In this case, the validator will verify that the email address has not been reported as a spammer.

For more information on how to create and use validation rules, please refer to the [Cookbook](https://book.cakephp.org/4/en/core-libraries/validation.html#using-custom-validation-rules).

### How to configure the cache

[](#how-to-configure-the-cache)

This plugin uses the [HTTP Client](https://book.cakephp.org/4/en/core-libraries/httpclient.html)to make requests and get responses, which are inspected and processed one by one. This can take a lot of resources and generate a lot of network traffic. For this reason, the plugin uses the cache (except for error responses).

By default, the cache is active. You can enable or disable it using the `cache`option. Example:

```
$SpamDetector = new SpamDetector();
//Disables the cache
$SpamDetector->setConfig('cache', false);
//Re-enables the cache
$SpamDetector->setConfig('cache', true);
```

`StopSpam` will use the homonymous cache engine [defined in its bootstrap file](https://github.com/mirko-pagliai/cakephp-stop-spam/blob/master/config/bootstrap.php#L18).

If you want to use your own cache engine or if you want to use a different onfiguration than the default one, then you have to configure the `StopSpam`cache engine **before** loading the plugin. Example:

```
Cache::setConfig('StopSpam, [
    'className' => 'File',
    'duration' => '+1 month',
    'path' => CACHE,
    'prefix' => 'stop_spam_',
]);
```

For more information on how to configure a cache engine, please refer to the [Cookbook](https://book.cakephp.org/4/en/core-libraries/caching.html#configuring-cache-engines).

Pay particular attention to what is reported by [stopforumspam.org](https://www.stopforumspam.com/usage) :

> This API is NOT to be used as a general software firewall. Checking every incoming connection against the API will be treated as a denial of service attack against us and will result in the immediate blocking of any offending IP addresses.

For this reason, it is advisable to use the cache, limit the requests and use the session to mark a user as already verified.

Versioning
----------

[](#versioning)

For transparency and insight into our release cycle and to maintain backward compatibility, *cakephp-stop-spam* will be maintained under the [Semantic Versioning guidelines](http://semver.org).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~120 days

Recently: every ~149 days

Total

16

Last Release

732d ago

PHP version history (3 changes)1.0.0-beta1PHP &gt;=5.5.9

1.1.0PHP &gt;=7.2

1.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/56d4c91c4d1ce5952a13c723d4fd340f8a1220ba1ef0212bbdb9a6334c98b3b9?d=identicon)[mirko-pagliai](/maintainers/mirko-pagliai)

---

Top Contributors

[![mirko-pagliai](https://avatars.githubusercontent.com/u/293199?v=4)](https://github.com/mirko-pagliai "mirko-pagliai (150 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mirko-pagliai-cakephp-stop-spam/health.svg)

```
[![Health](https://phpackages.com/badges/mirko-pagliai-cakephp-stop-spam/health.svg)](https://phpackages.com/packages/mirko-pagliai-cakephp-stop-spam)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)[xemlock/htmlpurifier-html5

HTML5 support for HTML Purifier

1052.9M11](/packages/xemlock-htmlpurifier-html5)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
