Home > Article > PHP Framework > How to turn off csrf in laravel5.1
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.
#The operating environment of this article: Windows 10 system, Laravel version 9, Dell G3 computer.
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
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!