"Webpage has expired" $_SESSIONS in PHP

"Webpage has expired" $_SESSIONS in PHP

筱武穆 发布于 2021-11-26 字数 258 浏览 715 回复 3 原文

In my web-application I'm using $_SESSIONS but sometimes, when the users hits the backspace key he gets:

Webpage has expired

message.

Why is this happening? What can i do to avoid this?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

素染倾城色 2022-06-07 3 楼

Like Chad said, that's the result of going back to a page that was the result of a POST request. And like the comments said, you can't just replace a POST with a GET, because that's a bad idea for a variety of reasons.

However, you can combine the two: let the request be a POST, but issue a Location header redirect, which the browser will then execute as a GET. To the user this will look like a single operation, but to the browser it will be a POST followed by a GET, which effectively eliminates this issue.

椵侞 2022-06-07 2 楼

It also has to do with the cache control directives sent to the browser.
Take a look at http://de.php.net/manual/en/session.configuration.php and http://shiflett.org/articles/how-to-avoid-page-has-expired-warnings to learn more about the cache settings.

http://shiflett.org/articles/how-to-avoid-page-has-expired-warnings:

Recap

To avoid "Page Has Expired" warnings, set session.cache_limiter to private, and make sure that any form using the POST method submits to an intermediate processing page that redirects the user to a different URL.

和影子一齐双人舞 2022-06-07 1 楼

This doesn't have anything to do with $_SESSION variables, it has to do with you transferring information between pages using POST method. If you want to avoid it you need to use GET method instead of POST.