douyan2470 2017-07-27 21:59
浏览 100
已采纳

在laravel中连续两次运行Logout路由时,我得到csrf令牌不匹配错误

Suppose the user has opened two pages. In one of them, touches the logout button. Then on the other page, again, touch the logout button.

Which with error:

(1/1) TokenMismatchException

In VerifyCsrfToken.php (line 68)
At VerifyCsrfToken-> handle (object (Request), object (Closure)) in Pipeline.php (line 148) ......

. Do you have any solution?

  • 写回答

1条回答 默认 最新

  • dongtang1909 2017-07-28 14:21
    关注

    in App\Exceptions\Handler.php Return the user to the form with a new valid CSRF token, so the page will refreshed and logout button will not exist.

    public function render($request, Exception $exception)
    { 
       if($exception instanceof TokenMismatchException)
       { 
          return redirect()
                   ->back()
                   ->with('your msg');
       }
       return parent::render($request, $exception); 
    }
    

    this looking like, page was refreshed.

    Don't Replace POST with Get. It will not Safe And Standard.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同