Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- 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
- 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
- if ($_POST) {
- process_input($_POST);
- header("Location: $_SERVER[HTTP_REFERER]");
- exit;
- }
Add Comment
Please, Sign In to add comment