Detect Search Engine Bot using CrawlerDetect Library in PHP

Search engine bot also known as web crawler or spider is a type of bot that is used to index web content in order to present websites in search engine results. There might be cases when we want to detect if website visitor is a bot.

CrawlerDetect is a PHP library that allows to detect bots based on User-Agent request header.

Add CrawlerDetect library to composer.json file:

"require": {
    "jaybizzle/crawler-detect": "^1.2"

Install library from the command line:

composer install

We have created an instance of CrawlerDetect class. The isCrawler method returns true if bot is detected.


use Jaybizzle\CrawlerDetect\CrawlerDetect;

require_once __DIR__.'/vendor/autoload.php';

$detect = new CrawlerDetect();

if ($detect->isCrawler()) {
    echo 'Bot';

Leave a Comment

Your email address will not be published. Required fields are marked *