jaybizzle/crawler-detect
Detect bots, crawlers, and spiders in PHP by matching User-Agent and HTTP_FROM headers. CrawlerDetect recognizes thousands of known user agents, is regularly updated, lets you check current or provided user agents, and can return the matched crawler name.
CrawlerDetect is a PHP library for detecting bots, crawlers and spiders via the User-Agent and HTTP_FROM headers. It currently recognises thousands of user agents and is updated regularly.
composer require jaybizzle/crawler-detect
use Jaybizzle\CrawlerDetect\CrawlerDetect;
$CrawlerDetect = new CrawlerDetect;
// Check the user agent of the current visitor
if ($CrawlerDetect->isCrawler()) {
// true if a crawler user agent was detected
}
// Pass a user agent as a string
if ($CrawlerDetect->isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')) {
// true if a crawler user agent was detected
}
// Output the name of the bot that matched (if any)
echo $CrawlerDetect->getMatches();
If you find a bot, spider or crawler that CrawlerDetect fails to detect, please open a pull request that:
$data array in src/Fixtures/Crawlers.phptests/data/user_agent/crawlers.txtThe raw/Crawlers.json and raw/Crawlers.txt files are regenerated automatically by export.php after merge — no need to touch them.
If you're not able to submit a PR, open an issue with the user agent string and we'll take it from there.
CrawlerDetect has been ported to a number of other languages and frameworks. If you maintain a port not listed here, please open a PR.
| Platform | Project |
|---|---|
| Laravel | Laravel-Crawler-Detect |
| Symfony 2 / 3 / 4 | CrawlerDetectBundle |
| Yii2 | yii2-crawler-detect |
| Node.js / ES6 | es6-crawler-detect |
| Python | crawlerdetect |
| JVM (Java, Scala, Kotlin) | CrawlerDetect |
| .NET / .NET Core | NetCrawlerDetect |
| Ruby | crawler_detect |
| Go | crawlerdetect |
Parts of this library are based on the excellent MobileDetect.
Released under the MIT License.
How can I help you explore Laravel packages today?