Skip to content

berry.utils.CrawlerDetector

Nikos Siatras edited this page Oct 1, 2022 · 7 revisions

CrawlerDetector class implements methods to detect crawlers and bots, such as Googlebot, Bingbot, Ahrefsbot and others, visiting the website.

CrawlerDetector.getCrawlerName

Description

public function getCrawlerName():string

If the current client is a crawler then this method returns the crawler's name. Otherwise it returns "" (String empty)

Example

The following example initializes a CrawlerDetector object and checks if the current client visiting the website is a crawler.

require_once(__DIR__ . "/berry/utils.php"); // Include berry utils package

$crawlerDetector = new CrawlerDetector();
$crawlerName = $crawlerDetector->getCrawlerName();

if ($crawlerName != "")
{
    print "Crawler Detected: " . $crawlerName;
}