| 1 |
<p align="center"> |
| 2 |
<a href="https://crawlerdetect.io/" target="_blank"> |
| 3 |
<img src="https://crawlerdetect.io/og-image.png" width="100%" alt="CrawlerDetect" /> |
| 4 |
</a> |
| 5 |
</p> |
| 6 |
|
| 7 |
<p align="center"> |
| 8 |
<a href="https://crawlerdetect.io/" target="_blank"><strong>crawlerdetect.io</strong></a> |
| 9 |
</p> |
| 10 |
|
| 11 |
<p align="center"> |
| 12 |
<a href="https://github.com/JayBizzle/Crawler-Detect/actions"><img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/JayBizzle/Crawler-Detect/test.yml?branch=master&style=flat-square"></a> |
| 13 |
<a href="https://packagist.org/packages/jaybizzle/crawler-detect"><img alt="Downloads" src="https://img.shields.io/packagist/dm/JayBizzle/Crawler-Detect.svg?style=flat-square" /></a> |
| 14 |
<a href="https://packagist.org/packages/jaybizzle/crawler-detect"><img alt="Latest Version" src="https://img.shields.io/packagist/v/jaybizzle/Crawler-Detect.svg?style=flat-square" /></a> |
| 15 |
<a href="https://coveralls.io/github/JayBizzle/Crawler-Detect"><img alt="Coverage" src="https://img.shields.io/coveralls/JayBizzle/Crawler-Detect/master.svg?style=flat-square" /></a> |
| 16 |
<a href="https://github.com/JayBizzle/Crawler-Detect/blob/master/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-ff69b4.svg?style=flat-square" /></a> |
| 17 |
</p> |
| 18 |
|
| 19 |
## About |
| 20 |
|
| 21 |
**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. |
| 22 |
|
| 23 |
## Installation |
| 24 |
|
| 25 |
```bash |
| 26 |
composer require jaybizzle/crawler-detect |
| 27 |
``` |
| 28 |
|
| 29 |
## Usage |
| 30 |
|
| 31 |
```php |
| 32 |
use Jaybizzle\CrawlerDetect\CrawlerDetect; |
| 33 |
|
| 34 |
$CrawlerDetect = new CrawlerDetect; |
| 35 |
|
| 36 |
// Check the user agent of the current visitor |
| 37 |
if ($CrawlerDetect->isCrawler()) { |
| 38 |
// true if a crawler user agent was detected |
| 39 |
} |
| 40 |
|
| 41 |
// Pass a user agent as a string |
| 42 |
if ($CrawlerDetect->isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')) { |
| 43 |
// true if a crawler user agent was detected |
| 44 |
} |
| 45 |
|
| 46 |
// Output the name of the bot that matched (if any) |
| 47 |
echo $CrawlerDetect->getMatches(); |
| 48 |
``` |
| 49 |
|
| 50 |
## Contributing |
| 51 |
|
| 52 |
If you find a bot, spider or crawler that CrawlerDetect fails to detect, please open a pull request that: |
| 53 |
|
| 54 |
- adds the regex pattern to the `$data` array in `src/Fixtures/Crawlers.php` |
| 55 |
- adds the failing user agent string to `tests/data/user_agent/crawlers.txt` |
| 56 |
|
| 57 |
The `raw/Crawlers.json` and `raw/Crawlers.txt` files are regenerated automatically by `export.php` after merge — no need to touch them. |
| 58 |
|
| 59 |
If you're not able to submit a PR, open an issue with the user agent string and we'll take it from there. |
| 60 |
|
| 61 |
## Ports & Integrations |
| 62 |
|
| 63 |
CrawlerDetect has been ported to a number of other languages and frameworks. If you maintain a port not listed here, please open a PR. |
| 64 |
|
| 65 |
| Platform | Project | |
| 66 |
| --- | --- | |
| 67 |
| Laravel | [](https://github.com/JayBizzle/Laravel-Crawler-DetectLaravel-Crawler-Detect](https://github.com/JayBizzle/Laravel-Crawler-Detect](https://github.com/JayBizzle/Laravel-Crawler-Detect) | |
| 68 |
| Symfony 2 / 3 / 4 | [](https://github.com/nicolasmure/CrawlerDetectBundleCrawlerDetectBundle](https://github.com/nicolasmure/CrawlerDetectBundle](https://github.com/nicolasmure/CrawlerDetectBundle) | |
| 69 |
| Yii2 | [](https://github.com/AlikDex/yii2-crawler-detectyii2-crawler-detect](https://github.com/AlikDex/yii2-crawler-detect](https://github.com/AlikDex/yii2-crawler-detect) | |
| 70 |
| Node.js / ES6 | [](https://github.com/JefferyHus/es6-crawler-detectes6-crawler-detect](https://github.com/JefferyHus/es6-crawler-detect](https://github.com/JefferyHus/es6-crawler-detect) | |
| 71 |
| Python | [](https://github.com/moskrc/CrawlerDetectcrawlerdetect](https://github.com/moskrc/CrawlerDetect](https://github.com/moskrc/CrawlerDetect) | |
| 72 |
| JVM (Java, Scala, Kotlin) | [](https://github.com/nekosoftllc/crawler-detectCrawlerDetect](https://github.com/nekosoftllc/crawler-detect](https://github.com/nekosoftllc/crawler-detect) | |
| 73 |
| .NET / .NET Core | [](https://github.com/gplumb/NetCrawlerDetectNetCrawlerDetect](https://github.com/gplumb/NetCrawlerDetect](https://github.com/gplumb/NetCrawlerDetect) | |
| 74 |
| Ruby | [](https://github.com/loadkpi/crawler_detectcrawler_detect](https://github.com/loadkpi/crawler_detect](https://github.com/loadkpi/crawler_detect) | |
| 75 |
| Go | [](https://github.com/x-way/crawlerdetectcrawlerdetect](https://github.com/x-way/crawlerdetect](https://github.com/x-way/crawlerdetect) | |
| 76 |
|
| 77 |
## Credits |
| 78 |
|
| 79 |
Parts of this library are based on the excellent [](https://github.com/serbanghita/Mobile-DetectMobileDetect](https://github.com/serbanghita/Mobile-Detect](https://github.com/serbanghita/Mobile-Detect). |
| 80 |
|
| 81 |
## License |
| 82 |
|
| 83 |
Released under the [](LICENSEMIT License](LICENSE](LICENSE). |
| 84 |
|