Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Crawler Detect

Crawler Detect Laravel Package

jaybizzle/crawler-detect

Detect bots/crawlers/spiders in PHP by matching User-Agent and HTTP_FROM headers. CrawlerDetect recognizes thousands of known crawlers, lets you check the current request or a provided UA string, and returns the matched bot name.

View on GitHub
Deep Wiki
Context7

CrawlerDetect is a lightweight PHP library that identifies bots/crawlers/spiders by inspecting the User-Agent and optional HTTP_FROM headers. It ships with patterns for thousands of known crawlers, making it useful for analytics filtering, rate limiting, and bot-aware middleware.

Use it to check the current request or provide a User-Agent string directly, and optionally retrieve the matched bot name for logging or reporting.

  • Detects crawlers via User-Agent and HTTP_FROM
  • Covers 1,000s of bot signatures out of the box
  • Simple API: isCrawler() for checks, getMatches() for matched name
  • Accepts a custom User-Agent string for offline/testing scenarios
  • Community-driven signature updates via PRs and tests
Frequently asked questions about Crawler Detect
How do I integrate CrawlerDetect into Laravel middleware for request-level bot detection?
Create a middleware class extending `Closure` or `HandleCrawlerRequests` (if using the Laravel wrapper). Inject the `CrawlerDetect` instance via the constructor, then call `$crawlerDetect->isCrawler()` in the `handle()` method. Bind the middleware in `app/Http/Kernel.php` under the `$routeMiddleware` array for global or route-specific use.
Can I use CrawlerDetect to block specific bots (e.g., AhrefsBot) while allowing others (e.g., Googlebot)?
Yes. Use the `$data` array in `Fixtures/Crawlers.php` to customize rules—add `!AhrefsBot` to block it or `Googlebot` to whitelist it. For Laravel, override the config in `config/crawler-detect.php` to define granular blacklists/whitelists per endpoint or globally.
Does CrawlerDetect work with Laravel’s Blade templates for conditional content serving?
Yes. Use the `@crawler` directive (if using the Laravel wrapper) or manually inject the `CrawlerDetect` instance into your Blade views. Example: `@if(!app('crawler-detect')->isCrawler()) Show content to humans @endif`. For dynamic checks, pass the User-Agent string directly to `isCrawler()`.
What Laravel versions and PHP versions does jaybizzle/crawler-detect support?
The package supports PHP 7.1–8.4 and works with Laravel 5.5+. For Laravel 10+, ensure your `composer.json` dependencies align with the latest `jaybizzle/crawler-detect` (v1.3.x) and its PHP requirements. The core package is framework-agnostic but tested rigorously with modern Laravel versions.
How can I test CrawlerDetect in my Laravel application before deploying to production?
Use the `isCrawler()` method with a hardcoded User-Agent string (e.g., `$crawlerDetect->isCrawler('Bingbot')`) in your tests. For unit testing, mock the `Request` object to simulate bot traffic. The package’s 95%+ test coverage ensures reliability, but validate edge cases like spoofed headers in your CI pipeline.
Is CrawlerDetect suitable for high-traffic Laravel applications? What’s the performance impact?
Yes. Benchmarks show <1ms detection latency even with 1,000+ crawler patterns. For high-traffic apps, cache detection results in Laravel’s cache driver (e.g., Redis) or preload the `CrawlerDetect` instance as a singleton in `AppServiceProvider`. Avoid repeated regex checks for known bots like Googlebot.
How do I extend CrawlerDetect to detect custom bots (e.g., internal monitoring tools) not in the default list?
Edit the `$data` array in `Fixtures/Crawlers.php` or override the config in `config/crawler-detect.php`. Add a regex pattern for your bot’s User-Agent (e.g., `InternalMonitoringBot` with its signature) and submit a PR to the repo to contribute back. Test your additions with `tests/crawlers.txt` before deployment.
Can I combine CrawlerDetect with Laravel’s fail2ban or IP blocking middleware for auto-ban?
Yes. Use CrawlerDetect to identify bots, then integrate with Laravel’s `fail2ban` or middleware like `BlockThrottledRequests` to auto-ban persistent offenders. Log bot names via `getMatches()` and trigger IP blocks for suspicious patterns (e.g., `HTTP_FROM` spoofing). Pair with IP reputation checks for robustness.
What are the alternatives to CrawlerDetect for Laravel, and when should I choose them?
Alternatives include `spatie/bot-detector` (simpler, fewer patterns) or `league/uri` + custom regex (more control). Choose CrawlerDetect for its 1,000+ bot signatures, Laravel middleware support, and community-driven updates. Use `spatie/bot-detector` for lightweight needs or `league/uri` if you need fine-grained regex logic without a pre-built list.
How do I handle false positives (e.g., legitimate users misclassified as bots) in production?
Customize the `$data` array in `Fixtures/Crawlers.php` to refine patterns or use Laravel’s config to whitelist specific User-Agents. For edge cases, combine with JavaScript challenges (e.g., Cloudflare Bot Management) or IP-based allowlists. Monitor false positives via Laravel Telescope or Sentry to iteratively improve accuracy.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport