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.
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
ext-intl PHP extension is recommended otherwise symfony/polyfill-intl-idn is used.
This package is installable and autoloadable via Composer as middlewares/referrer-spam.
composer require middlewares/referrer-spamBy 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.