Home > PHP Framework > Laravel > body text

How to turn off csrf verification in laravel

藏色散人
Release: 2021-12-27 15:00:05
Original
2850 people have browsed it

How to turn off csrf verification in laravel: 1. Open Kernel.php and comment "App\Http\Middleware\VerifyCsrfToken"; 2. Open VerifyCsrfToken.php and specify the URL to be excluded from CSRF verification.

How to turn off csrf verification in laravel

The operating environment of this tutorial: Windows 7 system, Laravel version 5.1, DELL G3 computer.

How to turn off csrf verification in laravel?

Laravel 5.1 Turn off csrf verification:

Description:

Laravel has the CSRF function enabled by default, and sometimes the verification token may not be passed , it needs to be closed.

Method 1 (global shutdown):

Open the file: app\Http\Kernel.php

Put this line Comment out:

'App\Http\Middleware\VerifyCsrfToken'
Copy after login

Method 2 (partially closed):

Modify the app\Http\Middleware\VerifyCsrfToken.php file.

In protected $except = [], specify URLs to exclude from CSRF validation

Example:

protected $except = [
  //关掉以api开头的请求
  'api/*',
  //关掉带有.htm的请求
  '*.htm*' 
];
Copy after login

Related recommendations:The latest five Laravel video tutorial

The above is the detailed content of How to turn off csrf verification in laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template