Detect Search Engine Bot using CrawlerDetect Library in PHP

Detect Search Engine Bot using CrawlerDetect Library in PHP

A 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 a 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.

<?php use Jaybizzle\CrawlerDetect\CrawlerDetect; require_once __DIR__.'/vendor/autoload.php'; $detect = new CrawlerDetect(); if ($detect->isCrawler()) { echo 'Bot'; }

Leave a Comment

Cancel reply

Your email address will not be published.