浏览PHP表单提交 [英] navigate back with PHP form submission

查看:742
本文介绍了浏览PHP表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这里是交易,
我使用HTML表单来传输页面间的变量和PHP脚本,以基于提交的值创建页面。
一般来说,它看起来像这样:从您选择想要的项目目录开始,下一个页面显示此特定项目的详细信息。除了一件事情之外,一切都很完美:



每当我使用浏览器的后退按钮时,我总会收到错误: ERR_CACHE_MISS ,我需要刷新页面然后确认我真的想重新提交数据。

有什么方法可以解决这个问题,所以我的客户只需按照他们应该使用的后退按钮即可。



以下是浏览器为我提供的全文:


此网页需要您之前输入的数据才能正确显示
。您可以再次发送这些数据,但通过这样做
您可以重复此页执行的任何操作。重新加载这
网页。按下重新加载按钮重新提交加载
页面所需的数据。错误代码:ERR_CACHE_MISS



解决方案

当您使用php或其他任何数据发布表单时,可能会回到页面并在浏览器中找到类似文档已过期或使用Chrome确认表单重新提交的消息。这些消息是浏览器使用敏感数据(如post变量)的安全防范措施。浏览器不会再自动给你新的页面。您必须重新加载页面,方法是再次单击尝试或刷新页面。然后,它按照您的预期运行。然而,php编码器可以通过在脚本中添加一些代码来解决来自浏览器的烦人消息。该示例显示了几行代码,可以在session_start()之上添加代码,以便当您发布时没有任何挂断时能够来回访问该页面。private_no_expire模式意味着客户端不会收到

  header('Cache-Control:no cache'); //没有缓存
session_cache_limiter('private_no_expire'); //作品
// session_cache_limiter('public'); //作品也是
session_start();


So here is the deal, I am using HTML forms to transfer variables from page to page and PHP script to create pages based on values submitted. In general it looks like this: from the catalog of items you select what you want and the next page shows details for this specific item. Everything works perfect, except one thing:

Whenever I use browser's back button, I always get the error: ERR_CACHE_MISS and I need to refresh page and then confirm that I really want to resubmit data.

Is there any way to fix this, so my customers would be able just to use back button as they supposed to.

Here is the full text that browser provides me:

This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed. Reload this webpage. Press the reload button to resubmit the data needed to load the page. Error code: ERR_CACHE_MISS

解决方案

When you post forms with php, or any other data, you may come back to the page and find a message in the browser like "Document Expired" or "Confirm Form Resubmission With Chrome". These messages are a safety precaution the browser uses with sensitive data such as post variables. The browser will not automatically give you the fresh page again. You must reload the page by clicking try again or with a page refresh. Then, it operates as you would expect it to.

However, the php coder can work around the annoying message from the browser by adding a little code into the script. The example shows a couple of lines of code that can be added above session_start() in order to be able to go back and forth to the page when you post without any hangups.The 'private_no_expire' mode means that the client will not receive the expired header in the first place.

header('Cache-Control: no cache'); //no cache
session_cache_limiter('private_no_expire'); // works
//session_cache_limiter('public'); // works too
session_start();

这篇关于浏览PHP表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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