【问题标题】:Laravel 7 419 Page Expired in POST methodsLaravel 7 419 页面在 POST 方法中过期
【发布时间】:2020-09-17 08:33:18
【问题描述】:

我已经在cpanel 上上传了一个 Laravel 7 项目。所有post 方法都会给出419 - page expired 错误,但在localhost 中可以正常工作。

我已将所有@csrfs 准确地设置在表单上。我在env 文件中设置了会话域。但是还是不行。

相反,它返回:

TokenMismatchException in VerifyCsrfToken.php line 53

【问题讨论】:

  • Cpanel 有时也有这个问题。尝试在本地做 php artisan cache:clear 并再次上传
  • 在 cPanel 上传你的 laravel 项目之前,清除你的缓存、配置、路由和视图
  • ^ 我很想知道缓存与 csrf 令牌有什么关系...?

标签: laravel csrf laravel-7


【解决方案1】:

我通过将网站从 http 迁移到 https 解决了这个问题

【讨论】:

    【解决方案2】:

    像这样在 .blade.php 文件 {{ csrf_field() }} 或 @csrf 中添加表单

    <form method='POST' action='route("exampleRoute")'>
       {{ csrf_field() }} or @csrf
    
          <div class="form-group">
                <label for="exampleInputEmail1">STitle</label>
                <input type="text" name='title' class="form-control" id="exampleInputEmail1" value="">
          </div>
       ....
       ....
    </form>
    

    【讨论】:

      【解决方案3】:

      你的标题中有 CSRF 吗?

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

      【讨论】:

        猜你喜欢
        • 2021-08-30
        • 1970-01-01
        • 1970-01-01
        • 2020-10-07
        • 2020-09-28
        • 2019-08-15
        • 2020-05-22
        • 2022-06-11
        • 2021-04-22
        相关资源
        最近更新 更多