Home  >  Article  >  PHP Framework  >  How to turn off csrf verification in laravel

How to turn off csrf verification in laravel

藏色散人
藏色散人Original
2021-12-27 14:30:592837browse

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'

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*' 
];

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!

Statement:
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