[英]419 Page Expired In Laravel Even after adding CSRF token
I am working on a Laravel 8 Framework, I have added the application on the live Cpanel server and then it started showing below Error:我正在开发一个 Laravel 8 框架,我在实时 Cpanel 服务器上添加了应用程序,然后它开始显示以下错误:
419 PAGE EXPIRED 419 页面过期
I know generally missing CSRF token will be the main issue but in this, I have added the CSRF token, I am using LARAVEl blade syntax so adding LARAVEL blade form syntax the "Token" (CSRF) will get added directly.我知道通常缺少 CSRF 令牌将是主要问题,但在此,我添加了 CSRF 令牌,我使用的是 LARAVEl 刀片语法,因此添加 LARAVEL 刀片形式语法将直接添加“令牌”(CSRF)。
{{ Form::open( [ "url" => \URL::route("front.login.check"), "autocomplete"=>false,"id" => "login_form" ] ) }}
This will add the CSRF automatically, I have tried adding directly, But every POST
request end up on the 419 PAGE EXPIRED
page.这将自动添加 CSRF,我试过直接添加,但是每个POST
请求最终都会出现在419 PAGE EXPIRED
页面上。
What do I have checked already?我已经检查了什么?
CSRF Token
Is not missing in the Form
Form
中没有丢失CSRF Token
419
page我也检查了中间件,但是这个请求在表单提交后没有到达中间件,它将带到419
页面php artisan cache:clear
and dump-autoload
command but the issue is still.也尝试php artisan cache:clear
和dump-autoload
命令,但问题仍然存在。storage
, vendor
and cache
folder also.还为storage
、 vendor
和cache
文件夹添加了755权限。Please help me on this What next should I need to check for solve this issue?请帮我解决这个问题接下来我需要检查什么来解决这个问题?
Apply/go through all steps up to "step 12" BEFORE testing your application for this error.在测试您的应用程序是否存在此错误之前,应用/执行直到“第 12 步”的所有步骤。
.env file contents applying the above 3 steps. .env 文件内容应用上述 3 个步骤。
Change myapp.local to your application domain.将 myapp.local更改为您的应用程序域。
APP_URL="http://myapp.local"
SESSION_LIFETIME=1440
SESSION_DOMAIN=myapp.local
SESSION_SECURE_COOKIE=false
PUT
/ POST
/ DELETE
/etc.) HTTP requests.确保您提交 CSRF 令牌以及您的( PUT
/ POST
/ DELETE
/等)HTTP 请求。<input type="hidden" name="_token" value="{{ csrf_token() }}" />
). (即:确保此请求参数与您的 HTML 表单请求<input type="hidden" name="_token" value="{{ csrf_token() }}" />
)。<meta>
tag" inside the <head>
tag of all your master VIEW templates/layouts.在所有主视图模板/布局的<head>
标签内添加此“ <meta>
标签”。 Ie: resources/views/layouts/app.blade.php and resources/views/layouts/guest.blade.php and resources/views/welcome.blade.php即: resources/views/layouts/app.blade.php和resources/views/layouts/guest.blade.php和resources/views/welcome.blade.php
<meta name="csrf-token" content="{{ csrf_token() }}">
npm run dev
).然后,定义所需的 HTTP 请求标头并重新编译您应用的 static 资产( npm run dev
)。 resources/js/app.js资源/js/app.js$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"X-Requested-With": "XMLHttpRequest"
}
});
php artisan key:generate
). (即: php artisan key:generate
)。php artisan cache:clear
). (即: php artisan cache:clear
)。chmod -R 755 "storage/framework/sessions" && chmod -R 755 "bootstrap/cache"
). (即: chmod -R 755 "storage/framework/sessions" && chmod -R 755 "bootstrap/cache"
)。.env file contents .env 文件内容
Change myapp.local to your application domain.将 myapp.local更改为您的应用程序域。
SANCTUM_STATEFUL_DOMAINS="myapp.local"
.env file contents .env 文件内容
SESSION_DRIVER=file
Disable the browser cache .禁用浏览器缓存。 This may be beneficial during your development process.这在您的开发过程中可能是有益的。
Open your web browser, navigate to your application's home page, reload the current page, ignoring cached content.打开您的 web 浏览器,导航到您的应用程序主页,重新加载当前页面,忽略缓存内容。 (Ie: On Windows : Shift + F5
or Ctrl + Shift + r
and on Mac : ⌘ + Shift + r
). (即:在Windows 上: Shift + F5
或Ctrl + Shift + r
,在Mac上: ⌘ + Shift + r
)。
TEST YOUR APP!测试您的应用程序! Check if you still receive the error.检查您是否仍然收到错误。
Only perform the steps below if you reached step 12 and are still having the same error.如果您到达第 12 步并且仍然遇到相同的错误,请仅执行以下步骤。
A. Clear ALL web browser cache & cookies . A. 清除所有 web 浏览器缓存和 cookies 。 TEST YOUR APP!测试您的应用程序!
B. Open an entirely different web browser and test again. B. 打开一个完全不同的 web 浏览器并再次测试。 If you've been using Google Chome / Safari all along, try testing using Firefox. TEST YOUR APP!如果您一直在使用 Google Chome / Safari,请尝试使用 Firefox 进行测试。测试您的应用程序!
C. Restart your computer and test again. C,重启电脑再测试。 TEST YOUR APP!测试您的应用程序!
1- php artisan route:clear
1- php artisan route:clear
2- go to CSRF middleware and try to add "*" to your except array 2- go 到 CSRF 中间件并尝试将“*”添加到您的 except 数组
When this happened to me it was because I forgot to add 'name' attribute to my input in the form当这发生在我身上时,是因为我忘记在表单中的输入中添加“名称”属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.