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.
user-agent and http_from headers, allowing for custom rule additions (e.g., whitelisting Googlebot while blocking AhrefsBot).HandleCrawlerRequests) for request-level bot detection.AppServiceProvider for global access via app('crawler-detect').@if(!crawler()) ... @endif) for conditional content serving.composer require jaybizzle/crawler-detect, with no breaking changes in recent versions (v1.3.x).Request object, PSR-7, or raw headers), ensuring backward compatibility with legacy systems.jaybizzle/laravel-crawler-detect) provides pre-built middleware and service provider integrations.| Risk | Mitigation Strategy | Severity |
|---|---|---|
| False Positives | Customize $data array in Fixtures/Crawlers.php or extend via Laravel config (config/crawler-detect.php). |
Low |
| Header Spoofing | Combine with IP reputation checks (e.g., spamhaus) or JavaScript challenges for high-risk endpoints. |
Medium |
| Performance Overhead | Cache detection results in Laravel’s cache driver (e.g., Redis) for repeated requests. | Low |
| Maintenance Burden | Leverage community contributions (500+ PRs) or auto-updates via Laravel’s composer update. |
Low |
| PHP Version Support | Tested on PHP 7.1–8.4; ensure your Laravel version (e.g., Laravel 10+) aligns with dependencies. | Low |
Detection Granularity:
AhrefsBot only for /api/pricing) or globally?Googlebot, Bingbot) for analytics?Integration Scope:
InternalMonitoringBot)?Performance Tradeoffs:
Googlebot) to reduce API costs?Security Implications:
fail2ban or IP blocking middleware for auto-ban?Long-Term Maintenance:
CrawlerDetect in App\Http\Middleware\DetectCrawlers for request-level checks.AppServiceProvider for global access.@crawler directives for template logic.Illuminate\Http\Request or PSR-7 interfaces, ensuring future-proofing.| Phase | Action Items | Dependencies | Risks |
|---|---|---|---|
| Discovery | Audit current bot traffic (e.g., via Laravel logs or spamhaus). Identify high-impact crawlers. |
Analytics tools (e.g., Sentry) | False assumptions on traffic. |
| Proof of Concept | Implement basic middleware to log bot names. Validate false positive/negative rates. | jaybizzle/crawler-detect |
Detection accuracy gaps. |
| Core Integration | Register CrawlerDetect in AppServiceProvider. Add middleware to protect critical endpoints. |
Laravel 10+ | Middleware pipeline conflicts. |
| Advanced Features | Extend with rate limiting, content personalization, or auto-ban logic. | Laravel Queues, Cache | Complexity overhead. |
| Monitoring | Set up Laravel Telescope or Sentry to track bot detection events. | Monitoring tools | Alert fatigue. |
CrawlerDetect for edge cases).Phase 1: Basic Detection (2–3 days)
Googlebot, Bingbot).Phase 2: Endpoint Protection (3–5 days)
AhrefsBot from /api/pricing).Phase 3: Performance Optimization (2–4 days)
Phase 4: Advanced Features (5–7 days)
Phase 5: Monitoring & Maintenance (Ongoing)
composer update jaybizzle/crawler-detect).$data array in Fixtures/Crawlers.php or **override viaHow can I help you explore Laravel packages today?