Skip to content

Repository files navigation

Symfony Bot Detection Bundle

Latest VersionSoftware LicenseBuild StatusCode CoverageMutation testing

Detect if the user agent is a bot and act upon it. Under the hood this bundle uses the matomo-org/device-detector, but instead of just using that library this library has a very small subset of user agents that it checks first (i.e. major search engines). This makes it much faster in detecting those very common bots and hence speeds up your request cycle.

Installation

composer require setono/bot-detection-bundle

This installs and enables the plugin automatically if you're using Symfony Flex. If not, add the bundle manually to bundles.php.

Usage

You can use the bot detector in your services:

<?phpuseSetono\BotDetectionBundle\BotDetector\BotDetectorInterface;
finalclass YourService
{
privateBotDetectorInterface$botDetector;
publicfunction__construct(BotDetectorInterface$botDetector)
{
$this->botDetector = $botDetector;
}
publicfunctionyourAction(): void
{
if ($this->botDetector->isBotRequest()) {
// do something to this bot!
}
// ...
}
}

and you can use it inside your twig templates:

{% if is_bot_request() %}
I knew you where a bot!
{% endif %}

About

Easily detect bots in your Symfony application

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages