VerifyCsrfToken in Laravel framework solves the error,

Source: Internet
Author: User

VerifyCsrfToken in Laravel framework solves the error,

Preface

This article describes VerifyCsrfToken errors in the Laravel framework for your reference. I will not talk about them here. Let's take a look at the details.

Error Message

The following error occurs when submitting data using form post.

TokenMismatchException in VerifyCsrfToken.php line 67:in VerifyCsrfToken.php line 67at VerifyCsrfToken->handle(object(Request), object(Closure))

Post Data submission Error

Cause

Laravel recommends that the Middleware of VerifyCsrfToken be registered globally. It automatically verifies whether _ csrf token is valid for all Post, Put, and Delete requests.

Solution

Method 1. Add the following hidden domain code to the form.

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

Method 2: Add csrf_field to form

(Consistent with the above solution functions)

{!! csrf_field() !!}

Method 3. comment out the Kernel. php code

Open app \ Http \ Kernel. php and comment out the following code in the file.

\App\Http\Middleware\VerifyCsrfToken::class

Method 4. Modify the handle () method

Open \ app \ Http \ Middleware \ VerifyCsrfToken. php and add or modify handle () as follows:

Public function handle ($ request, \ Closure $ next) {// use CSRF // return parent: handle ($ request, $ next ); // disable CSRF return $ next ($ request );}

Supplement csrf Introduction


Csrf illustration

References

1. Laravel 5.3 document-CSRF attack principles and protection

2. Laravel 5.3 documentation-HTTP layer CSRF Protection

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.