返回按钮重新提交表单数据($_POST) [英] Back button re-submit form data ($_POST)

查看:34
本文介绍了返回按钮重新提交表单数据($_POST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是当上一页是由表单创建时,后退按钮会导致浏览器说页面已过期".

My problem is that the back button causes the browser to say something like "Page expired" when the previous page was created by a form.

示例:

  • page1:通过搜索提交的表单标准($_POST 请求,表单指向第2页)
  • page2:接收 $_POST 请求并显示结果(带有链接的用户列表,指向第3页)
  • page3:显示用户个人资料

现在,当访问者点击浏览器中的后退按钮时,它会显示类似页面已过期"的内容.

Now when the visitor clicks the back button in the browser it will show something like "Page expired".

取而代之的是上一页显示时没有警告(page2,带有用户列表)

Instead the previous page should be shown with no warnings (page2, with the userlist)

您如何应对这种行为?

推荐答案

如果您提交带有搜索参数的表单,您是在尝试获取一些数据,而不是修改一些数据.

If you are submitting a form with search parameters, you are trying to get some data, not modify some.

因此,您应该使用 HTTP GET 方法,而不是 POST :当您打算创建/修改数据时应该使用 POST,而当您打算获取一些数据时应该使用 GET.

So, you should use the HTTP GET method, and not POST : POST should be used when you intend to create/modify data, and GET should be used when you intend to fetch some data.

或者,如果您有一些必须完成的创建/修改操作:

Or, if you have some create/modify operation that has to be done :

  • 表单首先发布到第一页
    • 该页面执行一些操作(例如向数据库写入内容)
    • 然后使用 Location HTTP 标头重定向到另一个页面.
    • The form first POSTs to a first page
      • That page does some operations (like writing something to a database)
      • And then redirects to another page, using a Location HTTP header.

      请参阅维基百科上的发布/重定向/获取页面,了解有关此内容的信息.

      See the Post/Redirect/Get page on wikipedia, about this.

      这篇关于返回按钮重新提交表单数据($_POST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆