删除POST数据,因此后退按钮将不会显示Document Expired [英] Removing POST data so back button won't display Document Expired
问题描述
当我的页面发布信息时,我将所有$_POST
数据存储在单独的$_SESSION
变量中.我知道此页面的后退按钮是设计用来显示Document Expired
消息的.我的希望是使浏览器愚弄以为实际上根本没有任何$_POST
数据,因此不要在返回时显示Document Expired
消息.我正在强制彻底刷新页面,所以我担心接收旧数据,因为我已将其存储在会话中.
When my page does a post, I store all the $_POST
data in a separate $_SESSION
var. I know that a back button to this same page is by design to show the Document Expired
message. My hope is to fool the browser into thinking that there was really never any $_POST
data and so not to display the Document Expired
message when coming back to it. I am forcing a complete refresh of the page so I am not worried about receiving old data, since I have it stored in the session.
我已尝试unset($_POST)
希望此内容会保留在页面中.但是$_POST
数据必须缓存/存储,并通过刷新或后退按钮返回.我想做的事可能吗?有什么想法吗?
I have tried to unset($_POST)
hoping this will stay with the page. but the $_POST
data must be cached / stored and returns with a refresh or back button. Is what I am trying to do possible? Any ideas?
*更新* 我的解决方案/答案发布在下面.它发布到一个单独的表单,该表单将重定向回原始表单以进行处理.不知道为什么要投反对票.它已经工作了好几个月了,我不再收到Document Expired消息.它还可以防止重复发布.
* UPDATE * My solution / answer is posted below. It posts to a separate form, which redirects back to the original form for processing. Not sure why the down vote. It has been working great for months and I no longer receive Document Expired messages. It also prevents duplicate posting.
推荐答案
*更新* 这是我的解决方法.
* UPDATE * Here's my solution.
我知道,使用post-redirect-get时,POST通常会返回到同一页面进行处理,然后再使用GET从表单重定向到另一个目标.但是,我需要能够返回到原始页面进行重新编辑(例如在文档模型中,用户可以保存正在进行的工作).因此,执行POST到第二页并重定向回原始页面是我摆脱"EXPIRED"消息的想法,因为编辑表单将没有与之关联的帖子数据.我已经扩展了它(未显示)以包括$ _FILE和其他情况(例如,也将它与a href
一起使用).不知道为什么要投票.这已经工作了好几个月了,并且可以完成任务.我不再收到文档过期"消息.此外,所有$ _POST处理都在原始文件中完成.
I am aware that with post-redirect-get the POST is usually back to the same page for processing before being redirected away from the form with a GET to another destination. However, I need to be able to return to the original page for re-editing (as in a document model where the user can SAVE work in progress). Therefore doing the POST to a second page and redirecting back to the original was my idea of getting rid of the "EXPIRED" message since the editing form would not have post data associated with it. I have extended this (not shown) to include $_FILE and other situations (e.g. using it with a href
as well). Not sure why the downvote. This has been working great for months now and accomplishes the task. I no longer receive "Document Expired" messages. In addition, all $_POST processing is accomplished in the original file.
testform.php
testform.php
<?php
session_start();
if (isset($_GET) && count($_GET)>0){
// process get
var_dump($_GET);
}
if (isset($_SESSION['post-copy'])){
// return post vars to $_POST variable so can process as normal
$_POST = $_SESSION['post-copy'];
// unset the session var - with refresh can't double process
unset($_SESSION['post-copy']);
// process post vars
var_dump($_POST);
}
?>
<form method='post' action='__b.php?redirect=<?php echo $_SERVER['PHP_SELF'] ?>&help=me' enctype='multipart/form-data'>
<textarea name='descr' id='descr'>ABCD</textarea>
<input type='submit' value='Go'>
</form>
redirect.php
redirect.php
<?php
if (!isset($_SESSION)){
session_start();
}
if (isset($_POST)){
$_SESSION['post-copy'] = $_POST;
}
// retrieve the url to return to
if (isset($_GET['redirect'])){
$url = $_GET['redirect'];
}
// if multiple query string parameters passed in get, isolate the redirect so can build querystring with the rest
if (isset($_GET) && count($_GET) > 1){
$get = $_GET;
foreach ($get as $key => $val){
if ($key == 'redirect'){
// remove from rest of passed get query string
unset($get[$key]);
}
}
if (count($get) > 0){
$url .= (strpos($url,"?")===false ? "?" : "&") . http_build_query($get);
}
}
if ($url!==""){
header("Location: " . $url);
}
?>
这篇关于删除POST数据,因此后退按钮将不会显示Document Expired的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!