gpt4 book ai didi

php - 使用 Laravel 的 TokenMismatchException : in VerifyCsrfToken. php 第 33 行

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:16 25 4
gpt4 key购买 nike

尽管搜索了 Stack OverFlow 并尝试了在类似问题中提出的所有建议,但我仍在努力通过此异常。

我接管了这个网站,并负责让它在 AWS 上运行。目前,我没有做任何冒险的事情,只是将批处理复制到运行 Apache、PHP、beanstalk、Laravel 和 MariaDB 的 Linux AWS VM。

站点设置为使用数据库作为SessionCache Driver。我已经尝试将其更改为 filecookie 但两者都没有任何区别。

我已确保 key:generate 已运行并存储在 .env 文件中。我已经尝试了表单中所有不同版本的 csrf_token 输出,但均无济于事。

我很抱歉围绕同一问题发布另一个问题,但希望有其他一些想法可以帮助我。

我的表单中的一个片段....

<form method="post" accept-charset="utf-8" autocomplete="off">
<meta name="csrf-token" content="{{ csrf_token() }}">
<div class="form-group">
.......
</form>

根据@Script47 的建议,我修改了我的表格,遗憾的是,这也不起作用:

<form method="post" accept-charset="utf-8" autocomplete="off">
{!! csrf_field() !!}
<div class="form-group">
.......
</form>

更多片段:

路由 - web.php

Route::any('/signup', ['as' => 'jobseeker.signup', 'uses' => 'Jobseeker\JobseekerController@signup']);

Controller

        if ($this->request->isMethod('POST'))
{
$rules = [
'email' => 'email|required|unique:jobseekers,email',
'password' => 'required|min:6|confirmed',
];

$validation_messages = ['email.unique' => trans('messages.auth.email.unique.validation', ['login' => route('jobseeker.login'), 'forgot' => route('jobseeker.forgot')])];
$validation = Validator::make($this->request->all(), $rules, $validation_messages);

if ($validation->passes())
{
Unsubscriber::remove($this->request->get('email'));
$jobseeker = Jobseeker::register($this->request->get('email'), $this->request->get('password'));
$jobseeker->sendRegistrationNotification();
$this->auth->login($jobseeker);
return redirect()->route('account.details');
}

疯狂的是,这在现场环境中有效。但没有用,因为我复制了一份代码并在 AWS 上重新设置了它。

最佳答案

根据 documentation,你做错了:

Anytime you define a HTML form in your application, you should include a hidden CSRF token field in the form so that the CSRF protection middleware can validate the request. You may use the csrf_field helper to generate the token field:

所以应该是:

{{ csrf_field() }}

在你的表单中。 meta标签一般用于AJAX请求引用token。

关于php - 使用 Laravel 的 TokenMismatchException : in VerifyCsrfToken. php 第 33 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58065818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com