Solution sharing of Verifycsrftoken error problem in Laravel

Source: Internet
Author: User
This article mainly introduces to you about the Laravel framework of Verifycsrftoken Error problem resolution method, the text through the sample code introduced in very detailed, to everyone's study or work has a certain reference study, the need for friends to follow the small series to learn together.

Objective

This article mainly introduces about the Laravel framework in the Verifycsrftoken error problem related content, share out for everyone to reference the study, the following words do not say, come together to see the detailed introduction bar.

Error condition

When the form form is submitted for post, the following error condition is encountered.


Tokenmismatchexception in verifycsrftoken.php line 67:in verifycsrftoken.php line 67at verifycsrftoken->handle ( Object (Request), Object (Closure))

Post Data submission Error

Reason

Laravel recommends that the Verifycsrftoken middleware be registered globally, and that all Post,put,delete requests are automatically checked for legitimate _CSRF tokens.

Workaround

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


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

Method 2. Add Csrf_field in form form

(Consistent with the above workaround function)


{!! Csrf_field ()!!}

Method 3. Comment 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, add or modify the handle () method as follows:


Public function handle ($request, \closure $next) {  //using CSRF  //return parent::handle ($request, $next);  Disable CSRF  return $next ($request);}

Supplemental CSRF Introduction


CSRF schematic interpretation

Summarize

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.