php - "The page has expired due to inactivity"- Laravel 5.5

标签 php laravel csrf laravel-5.5

我的注册页面正在正确显示表单,并且表单中存在 CsrfToken ({{ csrf_field() }})。

表单 HTML

<form class="form-horizontal registration-form" novalidate method="POST" action="{{ route('register') }}">
        {{ csrf_field() }}
        ....
</form>

我正在为用户使用内置身份验证。除了路由和重定向之外,没有改变任何东西。

当我提交表单时(也刚刚重新加载),它给出了 页面由于不活动而过期。请刷新并重试。错误。

我是我错过了一件非常小的事情。但不确定它是什么。有什么帮助吗?

更新

发现问题。 session 驱动程序设置为数组。将其更改为文件,现在错误消失了。 但是如果我使用数组有什么问题呢?

最佳答案

如果您是直接通过搜索获得此答案,请确保您已使用 {{ csrf_field() }} 将 csrf token 添加到表单中像OP一样。


如果您将 session 驱动程序设置为文件:

可能与 storage_path 不可写有关。如果您使用基于文件的 session ,它会在此处存储有关 token 的 session 数据。可以通过 is_writable(config('session.files'))

进行验证

对于 OP, session 驱动程序设置为数组。数组仅用于测试。由于数据没有持久化,所以下次请求时无法比较token。

The array driver is used during testing and prevents the data stored in the session from being persisted.

https://laravel.com/docs/5.5/session#configuration


检查 config/session.php

最后,我刚刚遇到的一个问题是,我们有一个项目,它在 config/session.php 中有 session 域和安全设置,但开发站点没有使用 HTTPS (SSL/TLS)。这导致了这个一般错误,因为 session.secure 默认设置为 true。

关于php - "The page has expired due to inactivity"- Laravel 5.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46141705/

相关文章:

laravel - 解析错误: syntax error, unexpected '$kernel' (T_VARIABLE) in the index.php file

java - Laravel exec() 在队列作业中

security - 新标签页和浏览器窗口中的 CSRF token

php - 您如何扩展Themosis helpers.php函数?

javascript - 如何为使用 JS 创建的表单创建 CSRF 字段

俄语的php问题

javascript - 如何使用 JavaScript 更改第三方选择标签值

php - 从 PHP 回显 &lt;script&gt; 到 jQuery AJAX 会导致我的时间间隔出现问题

php - 删除 codeigniter 2.1.0 中的 index.php

php - Laravel 1048 列在存储数据时不能为 NULL