有没有偶然发现一个教程,你觉得它很有价值,但没有正确解释?这是我的困境。我知道THIS TUTORIAL有一定的价值,但我无法得到它。治愈“后退按钮布鲁斯”
- 你在哪里调用每个函数?
- 哪个函数应该叫做 先下哪个,哪个 第三?
- 将在应用程序的所有文件中调用所有函数吗?
- 有谁知道更好的方法治疗“后退按钮布鲁斯”?
我想知道这是否会引起包括文章作者在内的一些好的对话。我特别感兴趣的部分是控制后退按钮,以防止按下后退按钮时表单重复输入数据库。基本上,您希望通过在应用程序中执行脚本期间调用以下三个函数来控制后退按钮。教程中不清楚按照什么顺序调用函数(参见上面的问题)。
所有向前移动都是由 使用我的scriptNext函数执行的。这是在 的当前脚本中调用的 以激活新脚本。
function scriptNext($script_id) // proceed forwards to a new script { if (empty($script_id)) { trigger_error("script id is not defined", E_USER_ERROR); } // if // get list of screens used in this session $page_stack = $_SESSION['page_stack']; if (in_array($script_id, $page_stack)) { // remove this item and any following items from the stack array do { $last = array_pop($page_stack); } while ($last != $script_id); } // if // add next script to end of array and update session data $page_stack[] = $script_id; $_SESSION['page_stack'] = $page_stack; // now pass control to the designated script $location = 'http://' .$_SERVER['HTTP_HOST'] .$script_id; header('Location: ' .$location); exit; } // scriptNext
当任何脚本已经完成它的 处理它终止通过调用我的 scriptPrevious功能。这将使 从堆栈数组的末尾 中删除当前脚本,并重新激活数组中的前一个脚本。
function scriptPrevious() // go back to the previous script (as defined in PAGE_STACK) { // get id of current script $script_id = $_SERVER['PHP_SELF']; // get list of screens used in this session $page_stack = $_SESSION['page_stack']; if (in_array($script_id, $page_stack)) { // remove this item and any following items from the stack array do { $last = array_pop($page_stack); } while ($last != $script_id); // update session data $_SESSION['page_stack'] = $page_stack; } // if if (count($page_stack) > 0) { $previous = array_pop($page_stack); // reactivate previous script $location = 'http://' .$_SERVER['HTTP_HOST'] .$previous; } else { // no previous scripts, so terminate session session_unset(); session_destroy(); // revert to default start page $location = 'http://' .$_SERVER['HTTP_HOST'] .'/index.php'; } // if header('Location: ' .$location); exit; } // scriptPrevious
每当一个脚本被激活时,其 可以是通过scriptNext 或scriptPrevious功能或 因为返回按钮在 浏览器,它将调用下面 函数,以验证它是 当前脚本根据 程序堆栈的内容,如果不是,则采取 适当的操作。
function initSession() // initialise session data { // get program stack if (isset($_SESSION['page_stack'])) { // use existing stack $page_stack = $_SESSION['page_stack']; } else { // create new stack which starts with current script $page_stack[] = $_SERVER['PHP_SELF']; $_SESSION['page_stack'] = $page_stack; } // if // check that this script is at the end of the current stack $actual = $_SERVER['PHP_SELF']; $expected = $page_stack[count($page_stack)-1]; if ($expected != $actual) { if (in_array($actual, $page_stack)) {// script is within current stack, so remove anything which follows while ($page_stack[count($page_stack)-1] != $actual) { $null = array_pop($page_stack); } // while $_SESSION['page_stack'] = $page_stack; } // if // set script id to last entry in program stack $actual = $page_stack[count($page_stack)-1]; $location = 'http://' .$_SERVER['HTTP_HOST'] .$actual; header('Location: ' .$location); exit; } // if ... // continue processing } // initSession
采取的行动取决于是否 的 程序堆栈或不存在内当前脚本。有三种 可能性:
- 当前脚本不是$ page_stack阵中,在这种情况下是 不允许它继续。取而代之的是 替换为 末尾的脚本。
- 当前脚本位于 $ page_stack数组中,但它不是最后一个条目的 。在这种情况下,所有 下面的条目中的条目都被删除,即 。
- 当前脚本是$ page_stack数组中的最后一个条目 。这是 的预期情况。全部饮料 !
嗨,很高兴你进来了。我解决了我的问题与post/redirect /获取模式在这里建议,但你可以请详细说明教程。我非常想更好地理解它。 – clientbucket 2009-01-10 08:01:08
我不同意你,但基于经验,我相当肯定我们将无法以有意义的方式讨论这个问题。我只想说,除了你的观点之外,还有其他的观点,让人们找出他们自己的答案。 – troelskn 2009-01-10 14:55:55