且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

没有机器人的Laravel会议

更新时间:2023-11-19 09:58:52

这就是我自己解决此问题的方式.

This is how I solved this for myself.

  1. 包括使用composer的自动程序检测程序包.我用了这个: https://github.com/JayBizzle/Crawler-Detect

composer require jaybizzle/crawler-detect

创建一个新的中间件类


namespace App\Http\Middleware;

class NoSessionForBotsMiddleware
{
    public function handle($request, \Closure $next)
    {
        if ((new \Jaybizzle\CrawlerDetect\CrawlerDetect)->isCrawler()) {
            \Config::set('session.driver', 'array');
        }

        return $next($request);
    }
}

  1. Kernel类中注册中间件 之前的会话:
  1. Register the middleware before session middleware in the Kernel class:


protected $middlewareGroups = [
    'web' => [
        // ..
        NoSessionForBotsMiddleware::class,
        StartSession::class,
        // ..
    ],
    // ..
];