Php ';照亮\会话\令牌不匹配异常';关于拉威尔5号

Php ';照亮\会话\令牌不匹配异常';关于拉威尔5号,php,debugging,laravel-5,csrf,Php,Debugging,Laravel 5,Csrf,我遇到了很多这样的错误: [2015-06-25 18:27:00] production.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /home/xxx/public_html/vendor/compiled.php:2550 Stack trace: #0 /home/xxx/public_html/app/Http/Middleware/VerifyCsrfToken.php(17): Illuminate

我遇到了很多这样的错误:

[2015-06-25 18:27:00] production.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /home/xxx/public_html/vendor/compiled.php:2550
Stack trace:
#0 /home/xxx/public_html/app/Http/Middleware/VerifyCsrfToken.php(17): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#1 /home/xxx/public_html/vendor/compiled.php(9197): App\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#2 /home/xxx/public_html/vendor/compiled.php(12377): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#3 /home/xxx/public_html/vendor/compiled.php(9197): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 /home/xxx/public_html/vendor/compiled.php(11067): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#5 /home/xxx/public_html/vendor/compiled.php(9197): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#6 /home/xxx/public_html/vendor/compiled.php(12079): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#7 /home/xxx/public_html/vendor/compiled.php(9197): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#8 /home/xxx/public_html/vendor/compiled.php(12027): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 /home/xxx/public_html/vendor/compiled.php(9197): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /home/xxx/public_html/vendor/compiled.php(2589): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 /home/xxx/public_html/vendor/compiled.php(9197): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#12 /home/xxx/public_html/vendor/platform/installer/src/Middleware/Installer.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#13 /home/xxx/public_html/vendor/compiled.php(9197): Platform\Installer\Middleware\Installer->handle(Object(Illuminate\Http\Request), Object(Closure))
#14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /home/xxx/public_html/vendor/compiled.php(9188): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#16 /home/xxx/public_html/vendor/compiled.php(1996): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /home/xxx/public_html/vendor/compiled.php(1983): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#18 /home/xxx/public_html/public/index.php(68): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#19 {main}  
我无法准确地找到它们的来源,因为该网站有很多流量

我在每一页的顶部都有这样的内容:

<meta name="csrf-token" content="{{ csrf_token() }}">

我所有的表格都有:

<input type="hidden" name="_token" value="{{ csrf_token() }}">

我不想像人们在其他帖子上建议的那样删除CSRF

你知道我如何调试它以找出错误的来源吗?只是寻找有助于发现错误的调试思想


非常感谢。

好的,看来这些错误是由外部世界向我的网站发出的POST请求引起的。目前,我已禁用CSRF,但计划实施如下解决方案:

只需运行这些命令

php artisan clear-compiled
composer dump-autoload

您可以捕获异常并按如下方式刷新用户:

    if ($exception instanceof TokenMismatchException) {
        return response()->redirect('login')->with('status', 'Token expired, please try again.');
    }

将其放入
App\Exceptions\Handler::render()

是否通过ajax请求表单数据?您的会话工作正常吗?请回答@DavidDomain问题,并包括您的formsHello的代码,是的,会话工作正常,我不使用AJAX。你认为可能是API在没有CSRF的情况下向我的站点发出POST请求吗?禁用CSRF是个糟糕的主意。请看我的答案。