【问题标题】:Laravel CSRF protection exception now workingLaravel CSRF 保护异常现在工作
【发布时间】:2019-11-02 06:40:13
【问题描述】:

我的 Laravel 项目在这个链接中

http://localhost/demo/public // laravel project

我有这个外部 HTML 表单

http://localhost/attendance

现在我想将表单中的数据发送到 Laravel 但我收到了这个错误

419 页面已过期

所以在我的 laravel 项目 VerifyCsrfToken 类中我写了这个

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'http://localhost/attendance'
    ];
}

但还是出现了同样的错误

419 页面已过期

【问题讨论】:

    标签: php laravel csrf csrf-token


    【解决方案1】:

    Laravel 为您解析应用程序的 baseUrl,无需放置完整路径,在您的情况下,中间件应如下所示:

    class VerifyCsrfToken extends Middleware
    {
        /**
         * The URIs that should be excluded from CSRF verification.
         *
         * @var array
         */
        protected $except = [
            'attendance/*'
        ];
    }
    

    【讨论】:

    • 现在是否使用与演示文件无关的相同考勤文件
    • 您想从所有 urls 项目中获得 csrf_token 还是仅仅从出勤或出勤的子链接中获得 csrf_token?
    • 仅来自考勤的子链接
    • 如果您的应用程序中的考勤组子链接,请检查我的编辑答案
    【解决方案2】:
    • 一种解决方案是将数据作为 GET 请求而不是 POST 请求发送。

    • 一旦您将作品放到网上,您将面临浏览器的跨站点保护。

    • 要排除的URI是接收请求的http://localhost/demo/public

    【讨论】:

    • 有时数据超过 1000 个,所以它会打开 1000 个浏览器,我不想像以前那样工作
    猜你喜欢
    • 2018-05-27
    • 1970-01-01
    • 2011-06-27
    • 2017-05-04
    • 2016-09-05
    • 2015-03-11
    • 2015-12-01
    • 2012-07-23
    • 2014-09-23
    相关资源
    最近更新 更多