Download the PHP package mkopcic/laravel-bot-protection without Composer

On this page you can find all versions of the php package mkopcic/laravel-bot-protection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-bot-protection

# 🤖🛡️ Laravel Bot Protection **Block AI crawlers, search engines, and known scrapers from your Laravel app — with one line of `composer require`.** [![Latest Version on Packagist](https://img.shields.io/packagist/v/mkopcic/laravel-bot-protection.svg?style=flat-square)](https://packagist.org/packages/mkopcic/laravel-bot-protection) [![Tests](https://img.shields.io/github/actions/workflow/status/mkopcic/laravel-bot-protection/tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/mkopcic/laravel-bot-protection/actions/workflows/tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/mkopcic/laravel-bot-protection.svg?style=flat-square)](https://packagist.org/packages/mkopcic/laravel-bot-protection) [![License](https://img.shields.io/packagist/l/mkopcic/laravel-bot-protection.svg?style=flat-square)](LICENSE) [![PHP Version](https://img.shields.io/packagist/php-v/mkopcic/laravel-bot-protection.svg?style=flat-square)](composer.json) [![Laravel](https://img.shields.io/badge/Laravel-10%20%7C%2011%20%7C%2012%20%7C%2013-FF2D20?style=flat-square&logo=laravel)](composer.json)

📖 About

laravel-bot-protection is a drop-in middleware package that protects Laravel applications from unwanted automated traffic — AI training crawlers, LLM agents, SEO bots, and generic scrapers. It blocks known bot User-Agents with HTTP 403 and adds the X-Robots-Tag: noindex, nofollow header to every response so well-behaved crawlers (Google, Bing, etc.) also skip indexing.

Built for production apps where you need zero-config setup but fine-grained control when you want it.


✨ Features


📋 Requirements

Requirement Version
PHP ^8.1
Laravel 10.x, 11.x, 12.x, 13.x

📦 Installation

That's it. Laravel package auto-discovery registers the service provider and pushes the middleware into the web group. Your app is now protected.

🎨 Publishing assets (optional)

Tag What it publishes Destination
bot-protection-config Configuration file config/bot-protection.php
bot-protection-robots Comprehensive robots.txt public/robots.txt ⚠️ overwrites!
bot-protection-server Nginx + Apache + .htaccess snippets bot-protection/
bot-protection Config + server stubs (everything except robots.txt) mixed

🚀 Quick Start

After installation, verify the protection works:

You should see ✓ BLOCKED [403] for each agent.


⚙️ Configuration

All settings can be controlled via environment variables (no need to publish config):

For custom blocked agent lists, publish the config and edit config/bot-protection.php.


🎨 Blade Directive — @botProtectionMeta

Drop one line into your <head> and the package renders the standard robots meta tags using your configured x_robots_tag value:

Renders:

The last <meta> is the AI opt-out directive — an emerging standard adopted by DeviantArt, ArtStation, Squarespace. Some AI scrapers already respect it. Disable via BOT_PROTECTION_AI_META_TAGS="".

If both x_robots_tag and ai_meta_tags are empty, the directive renders nothing.


🔄 Dynamic /robots.txt Route

Instead of publishing a static public/robots.txt and keeping it in sync with your config, opt in to a dynamic route:

The package registers GET /robots.txt that emits content generated from your blocked_agents config. Change the config → robots.txt updates instantly. Single source of truth.

⚠️ If public/robots.txt exists, your web server (Nginx/Apache) serves the static file first and the dynamic route never fires. Delete public/robots.txt for full dynamic behavior.


📡 BotBlocked Event

Every block fires a Mkopcic\BotProtection\Events\BotBlocked event with full request context. Listen to it for logging, alerting, or analytics:

Or use a dedicated listener class:


📝 Built-in Logging

If you don't need custom event handling, just turn on logging:

Every blocked request writes a warning to the chosen channel with user_agent, ip, url, and matched_agent in the context.


🛠️ Manual Middleware Registration

If you want full control (e.g. apply only to specific route groups), disable auto-register:

Then register manually.

Laravel 11 / 12 / 13 — in bootstrap/app.php:

Laravel 10 — in app/Http/Kernel.php:

Or apply per-route:


🧪 Artisan Command — bot-protection:test

The package ships with a built-in tester with two subactions: url and config.

config — dump current configuration

Outputs all settings, allowed IPs, and the full list of blocked agents.

url — fire HTTP requests with bot User-Agents

Sample output:

Returns exit code 0 if all agents are blocked, 1 if any get through.


🌐 Server-Level Protection (Recommended)

The middleware protects at the Laravel layer. For defense in depth, block bots at the web server too — they never reach PHP, saving CPU.

Publish the server config examples:

You'll get a bot-protection/ directory with:

File Use
nginx-shared-map.conf Drop in /etc/nginx/conf.d/ once — defines $blocked_bot map for all vhosts
nginx-vhost-snippet.conf Paste into each Nginx server {} block
apache-vhost-snippet.conf Full Apache vhost example with SetEnvIf
htaccess-snippet.txt .htaccess rules (when you can't edit vhosts)

🧬 How It Works


🧪 Running Tests

13 Pest tests cover:


🤖 What's Blocked Out of the Box

Click to expand the full list (33 agents) | Category | Agents | | --- | --- | | **OpenAI** | GPTBot, ChatGPT-User, OAI-SearchBot | | **Anthropic** | ClaudeBot, anthropic-ai, Claude-Web | | **Google** | Google-Extended, Googlebot, AdsBot-Google | | **Meta** | Meta-ExternalAgent, FacebookBot, facebookexternalhit | | **Apple** | Applebot, Applebot-Extended | | **Amazon** | Amazonbot | | **Perplexity** | PerplexityBot | | **ByteDance** | Bytespider | | **Common Crawl** | CCBot | | **Cohere** | cohere-ai | | **Mistral** | MistralAI-User | | **Diffbot** | Diffbot | | **SEO crawlers** | SemrushBot, AhrefsBot, MJ12bot, DotBot, BLEXBot | | **Eastern engines** | YandexBot, Baiduspider, Sogou | | **Generic scrapers** | Scrapy, python-requests, curl/, wget/ |

You can add, remove, or fully override the list by publishing config and editing blocked_agents.


⚠️ What This Package Is NOT

For maximum protection: this package + server-level rules + authentication for sensitive content.


🔗 Related


🤝 Contributing

Contributions are welcome! Please open an issue or PR.

For new bot User-Agents to add to the default list, please include a source link (the bot's official documentation page).


📜 License

The MIT License (MIT). See LICENSE for details.


**Built with ❤️ for the Laravel community.** If this package saved your bandwidth or your sanity, ⭐ the repo!

All versions of laravel-bot-protection with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/routing Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mkopcic/laravel-bot-protection contains the following files

Loading the files please wait ...