PHP 5.6.9上的Laravel 5 TokenMismatchException [英] Laravel 5 TokenMismatchException on PHP 5.6.9

查看:55
本文介绍了PHP 5.6.9上的Laravel 5 TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布请求可以在PHP 5.4上运行Laravel 5应用正常运行.在 5.6.9 PHP上运行的相同应用上发布请求会生成:

Post requests work fine running Laravel 5 app on PHP 5.4. Post requests on the same app running on PHP 5.6.9 generate:

第46行的TokenMismatchException VerifyCsrfToken.php

TokenMismatchException VerifyCsrfToken.php on line 46

在WAMP和IIS上的每个发布请求中都会发生这种情况.发生使用数据库会话和文件会话的情况.是否进行了完全重新安装,并且还尝试了此处提出的所有建议: https://laracasts.com/discuss/channels/general-discussion/keep-getting-tokenmismatchexception-verifycsrftokenphp-on-line-46?page=2 .人们正在禁用Csrf中间件作为修复程序,但这不是可行的解决方案.任何帮助表示赞赏.

This happens on every post request on both WAMP and IIS. Happens using database sessions and file sessions. Did a full reinstall and also tried all suggestions made here: https://laracasts.com/discuss/channels/general-discussion/keep-getting-tokenmismatchexception-verifycsrftokenphp-on-line-46?page=2. Folks are disabling the Csrf middleware as a fix, but that is not a viable solution. Any help appreciated.

推荐答案

当我意识到这仅发生在IE和Chrome中,而没有在Firefox中发生时,它使我得以解决.该应用程序正在使用AddThis共享按钮,而javascript正在向页面添加iframe.通过将P3P标头添加到VerifyCsrfToken中间件,可以解决此问题.希望这可以为我节省一些时间.

When I realized this was only happening in IE and Chrome, but not Firefox, it led me to the fix. The app was using AddThis share buttons and the javascript was adding an iframe to the pages. This issue is resolved by adding a P3P header to the VerifyCsrfToken Middleware. Hope this saves somebody the hours I lost.

public function handle($request, Closure $next)
    {
        $response = $next($request);

        if (last(explode('\\',get_class($response))) != 'RedirectResponse') {
            $response->header('P3P', 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
        }

        return $response;
    }

这篇关于PHP 5.6.9上的Laravel 5 TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆