craigpotter / laravel-ie-honeypot
A small package to capture IE users and recommend they use a modern browser before they hit your site
Fund package maintenance!
craigpotter
Requires
- php: ^8.0.2
- illuminate/contracts: ^9.0
- illuminate/support: ^9.0
- spatie/laravel-package-tools: ^1.13.5
Requires (Dev)
- nunomaduro/collision: ^6.1
- orchestra/testbench: ^7.8.0
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-10-29 06:18:58 UTC
README
Web development should be a progressive journey and let's face it, we all hate Microsoft Internet Explorer. Have you had an issue where users were using IE, getting JS errors and then complaining about how your application is broken? This simple package might be for you then! Laravel IE Honeypot detects requests coming in to the app from users using IE and redirects to a page of your choice. This should be a simple page informing the user their browser is too old or maybe even link them to what they deserve
Installation
You can install the package via composer:
composer require craigpotter/laravel-ie-honeypot
You can publish the config file with:
php artisan vendor:publish --provider="CraigPotter\LaravelIEHoneypot\LaravelIEHoneypotServiceProvider" --tag="ie-honeypot-config"
This is the contents of the published config file:
return [ /** * This switch determines if the honeypot protection should be activated. */ 'enabled' => env('IE_HONEYPOT_ENABLED', true), /** * This switch determines the URL that IE users will get redirect to. */ 'redirect_url' => env('IE_HONEYPOT_REDIRECT_URL', '/ie-trap'), /** * This switch determines if the bypass functionality is enabled. * This will allow use of the @ieBypass directive and allow IE users to access your * site by adding ?ie-bypass=true to a url */ 'bypass_enabled' => env('IE_HONEYPOT_BYPASS_ENABLED', true), ];
Usage
If you want to display a page within your own application to your IE users, you should create a route with a simple layout and add the URL to your configuration file.
There are two main ways to use this package but both involve adding middleware to your routes.
Option 1
Add the middleware to indiviual routes in your routes file or to a group of routes. This option might be best if you have a single point of entry for your application. For example, Users have to login so you might choose to add it to your login route only.
use CraigPotter\LaravelIEHoneypot\CaptureIE; Route::get('/', [YourController::class])->middleware(CaptureIE::class); // OR Route::middleware(CaptureIE::class)->group(function() { // Routes });
Option 2
If you have a lot of routes or just need to keep those pesky IE Users off your site, you could register it as global middleware
// app\Http\Kernal.php protected $middleware = [ // ... \CraigPotter\LaravelIEHoneypot\CaptureIE::class, ];
Bypass
If the bypass_enabled
option is true in your configuration, the middleware will allow any user to a path if it has a url param of ie-bypass=true
.
You can share links with this bypass if you need to e.g https://your-app.com/contact-us?ie-bypass=true
You also have the option to add this to your own bypass page to allow users to proceed at their own risk.
For example, if a user visits /contact-us
with an IE browser, they would be redirected to our redirect_url
, you can use the @ieBypass
blade directive to automatically generate the bypass url for the initial page visited. In this case, it would be /contact-us?ie-bypass=true
.
If we look at the view for that page:
<div> <h1>Use a better browser!> <a href="@ieBypass">Click here to proceed at your own risk</a> </div>
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.