jaybizzle / crawler-detect
CrawlerDetect is a PHP class for detecting bots/crawlers/spiders via the user agent
Requires
- php: >=7.2.0
Requires (Dev)
- phpunit/phpunit: ^8.5.52|^9.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.11
- v1.3.10
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.121
- v1.2.120
- v1.2.119
- v1.2.118
- v1.2.117
- v1.2.116
- v1.2.115
- v1.2.114
- v1.2.113
- v1.2.112
- v1.2.111
- v1.2.110
- v1.2.109
- v1.2.108
- v1.2.107
- v1.2.106
- v1.2.105
- v1.2.104
- v1.2.103
- v1.2.102
- v1.2.101
- v1.2.100
- v1.2.99
- v1.2.98
- v1.2.97
- v1.2.96
- v1.2.95
- v1.2.94
- v1.2.93
- v1.2.92
- v1.2.91
- v1.2.90
- v1.2.89
- v1.2.88
- v1.2.87
- v1.2.86
- v1.2.85
- v1.2.84
- v1.2.83
- v1.2.82
- v1.2.81
- v1.2.80
- v1.2.79
- v1.2.78
- v1.2.77
- v1.2.76
- v1.2.75
- v1.2.74
- v1.2.73
- v1.2.72
- v1.2.71
- v1.2.70
- v1.2.69
- v1.2.68
- v1.2.67
- v1.2.66
- v1.2.65
- v1.2.64
- v1.2.63
- v1.2.62
- v1.2.61
- v1.2.60
- v1.2.59
- v1.2.58
- v1.2.57
- v1.2.56
- v1.2.55
- v1.2.54
- v1.2.53
- v1.2.52
- v1.2.51
- v1.2.50
- v1.2.49
- v1.2.48
- v1.2.47
- v1.2.46
- v1.2.45
- v1.2.44
- v1.2.43
- v1.2.42
- v1.2.41
- v1.2.40
- v1.2.39
- v1.2.38
- v1.2.37
- v1.2.36
- v1.2.35
- v1.2.34
- v1.2.33
- v1.2.32
- v1.2.31
- v1.2.30
- v1.2.29
- v1.2.28
- v1.2.27
- v1.2.26
- v1.2.25
- v1.2.24
- v1.2.23
- v1.2.22
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.17
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-crawler-categories
This package is auto-updated.
Last update: 2026-11-11 18:47:37 UTC
README
About
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.
Installation
composer require jaybizzle/crawler-detect
Usage
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 part of the user agent that matched (if any) echo $CrawlerDetect->getMatches();
Passing headers from a request object
With no arguments, CrawlerDetect reads $_SERVER. If your headers come from somewhere else — a PSR-7 request, Symfony's HeaderBag, Swoole, or a Lambda event — pass them in directly. Both real header names (User-Agent) and PHP's SAPI names (HTTP_USER_AGENT) are understood, and values may be strings or arrays of strings.
// PSR-7 (Slim, Mezzio, Laminas, League) $CrawlerDetect = new CrawlerDetect($request->getHeaders()); // Symfony HttpFoundation $CrawlerDetect = new CrawlerDetect($request->headers->all()); // Swoole $CrawlerDetect = new CrawlerDetect($request->header); if ($CrawlerDetect->isCrawler()) { // ... }
Prefer this over isCrawler($request->getHeaderLine('User-Agent')). Some crawlers — Googlebot in particular — send a genuine browser User-Agent and identify themselves in another header such as From or Sec-CH-UA. Passing the full set lets CrawlerDetect check all of them; passing a single string can only ever check one.
Contributing
If you find a bot, spider or crawler that CrawlerDetect fails to detect, please open a pull request that:
- adds the regex pattern to the
$dataarray insrc/Fixtures/Crawlers.php - adds the failing user agent string to
tests/data/user_agent/crawlers.txt
The 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.
Ports & Integrations
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 |
| Node.js / ES6 | es6-crawler-detect |
| Python | crawlerdetect |
| .NET / .NET Core | NetCrawlerDetect |
| Ruby | crawler_detect |
| Go | crawlerdetect |
These ports are no longer maintained and do not receive new crawler signatures:
| Platform | Project | Last updated |
|---|---|---|
| Symfony 2 / 3 / 4 | CrawlerDetectBundle | 2021 |
| Yii2 | yii2-crawler-detect | 2016 |
| JVM (Java, Scala, Kotlin) | CrawlerDetect | 2022 |
Security
Please don't report security issues in the public issue tracker. See SECURITY.md for how to report one privately.
Credits
Parts of this library are based on the excellent MobileDetect.
License
Released under the MIT License.