middlewares/referrer-spam

Middleware to block referrer spammers

v2.0.3 2022-09-27 11:27 UTC

This package is auto-updated.

Last update: 2024-10-27 15:37:25 UTC


README

Latest Version on Packagist Software License Testing Total Downloads

Middleware to block referrer spammers using matomo/referrer-spam-blacklist. It returns a 403 response if the url host in the Referer header is in the blacklist.

Requirements

ext-intl PHP extension is recommended otherwise symfony/polyfill-intl-idn is used.

Installation

This package is installable and autoloadable via Composer as middlewares/referrer-spam.

composer require middlewares/referrer-spam

Usage

By default, use matomo/referrer-spam-blacklist as a list of spammers

$spam = new Middlewares\ReferrerSpam();

But you can configure a custom spam list if you don't want to use the default:

$spammers = [
    'http://www.0n-line.tv',
    'http://холодныйобзвон.рф',
];

$spam = new Middlewares\ReferrerSpam($spammers);

Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument to create the error responses (403). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$responseFactory = new MyOwnResponseFactory();

$spam = new Middlewares\ReferrerSpam($spammers, $responseFactory);

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.