Home >PHP Framework >Laravel >How to turn off csrf in laravel5.1

How to turn off csrf in laravel5.1

WBOY
WBOYOriginal
2022-06-21 16:31:032904browse

Method: 1. Comment out the "App\Http\Middleware\VerifyCsrfToken" code in the "app\Http\Kernel.php" file to turn off csrf globally; 2. In the "app\Http\Middleware\ Modify the "protected $except" content in the "VerifyCsrfToken.php" file and specify the URLs excluded from CSRF verification to partially turn off csrf.

How to turn off csrf in laravel5.1

#The operating environment of this article: Windows 10 system, Laravel version 9, Dell G3 computer.

How to turn off csrf in laravel5.1

Laravel has the CSRF function turned on by default. Sometimes the verification token may not be passed, so it needs to be turned off.

Method 1 (global shutdown):

Open the file: app\Http\Kernel.php

Comment out this line:

'App\Http\Middleware\VerifyCsrfToken'

Method 2 (partially closed):

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

In protected $except = [], specify the URLs to be excluded from CSRF verification

How to turn off csrf in laravel5.1

Example:

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

[Related recommendations: laravel video tutorial

The above is the detailed content of How to turn off csrf in laravel5.1. 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
Previous article:what laravel queue can doNext article:what laravel queue can do