craigpotter / laravel-ie-honeypot
一个小型包,用于捕捉使用IE的用户,并在他们访问您的网站之前推荐他们使用现代浏览器
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-08-29 05:37:25 UTC
README
网络开发应该是一个渐进的过程,让我们面对现实,我们都不喜欢微软的Internet Explorer。你是否遇到过用户使用IE,遇到JS错误然后抱怨你的应用程序是破烂的情况?这个简单的包可能就是为你准备的!Laravel IE Honeypot可以检测到应用中来自使用IE的用户请求,并将其重定向到您选择的页面。这应该是一个简单的页面,通知用户他们的浏览器太旧了,或者甚至可以链接到他们应得的
安装
您可以通过composer安装此包
composer require craigpotter/laravel-ie-honeypot
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="CraigPotter\LaravelIEHoneypot\LaravelIEHoneypotServiceProvider" --tag="ie-honeypot-config"
这是发布配置文件的内容
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), ];
用法
如果您想在您的应用程序中向IE用户显示一个页面,您应该在路由文件中创建一个带有简单布局的路由,并将URL添加到配置文件中。
使用此包有两种主要方式,但两种方式都涉及到在路由中添加中间件。
选项1
将中间件添加到路由文件中的单个路由或路由组。如果您的应用程序只有一个入口点,此选项可能最好。例如,用户必须登录,您可能选择将其添加到登录路由中。
use CraigPotter\LaravelIEHoneypot\CaptureIE; Route::get('/', [YourController::class])->middleware(CaptureIE::class); // OR Route::middleware(CaptureIE::class)->group(function() { // Routes });
选项2
如果您有很多路由或只是需要将那些讨厌的IE用户从您的网站上赶走,您可以将其注册为全局中间件
// app\Http\Kernal.php protected $middleware = [ // ... \CraigPotter\LaravelIEHoneypot\CaptureIE::class, ];
绕过
如果配置中的bypass_enabled选项为true,则中间件将允许用户访问任何路径,如果它有一个ie-bypass=true的URL参数。如果您需要共享绕过链接,可以使用此选项,例如https://your-app.com/contact-us?ie-bypass=true
您还有将此添加到自己的绕过页面的选项,以允许用户自行决定是否继续。例如,如果用户使用IE浏览器访问/contact-us,他们将被重定向到我们的redirect_url,您可以使用@ieBypass blade指令自动生成初始访问页面的绕过URL。在这种情况下,它将是/contact-us?ie-bypass=true。如果我们查看该页面的视图
<div> <h1>Use a better browser!> <a href="@ieBypass">Click here to proceed at your own risk</a> </div>
测试
composer test
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请参阅我们的安全策略以了解如何报告安全漏洞。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。