setono/bot-detection-bundle

A Symfony bundle that allows you to test if a user agent is a bot

Maintainers

πŸ‘ loevgaard

Package info

github.com/Setono/BotDetectionBundle

Type:symfony-bundle

pkg:composer/setono/bot-detection-bundle

Statistics

Installs: 125 407

Dependents: 8

Suggesters: 0

Stars: 8

Open Issues: 1

v1.13.0 2025-02-03 09:33 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 6ff94b30bb927eb9a282cbd718715cdd22dd1a43

  • Joachim LΓΈvgaard <joachim.woop@loevgaard.dk>

README

πŸ‘ Latest Version
πŸ‘ Software License
πŸ‘ Build Status
πŸ‘ Code Coverage
πŸ‘ Mutation 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:

<?php

use Setono\BotDetectionBundle\BotDetector\BotDetectorInterface;

final class YourService
{
 private BotDetectorInterface $botDetector;

 public function __construct(BotDetectorInterface $botDetector)
 {
 $this->botDetector = $botDetector;
 }

 public function yourAction(): 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 %}