Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 97137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:56:49+00:00 2026-05-10T23:56:49+00:00

Ever stumbled on a tutorial that you feel is of great value but not

  • 0

Ever stumbled on a tutorial that you feel is of great value but not quite explained properly? That’s my dilemma. I know THIS TUTORIAL has some value but I just can’t get it.

  1. Where do you call each function?
  2. Which function should be called first and which next, and which third?
  3. Will all functions be called in all files in an application?
  4. Does anyone know of a better way cure the ‘Back Button Blues’?

I’m wondering if this will stir some good conversation that includes the author of the article. The part I’m particularly interested in is controlling the back button in order to prevent form duplicate entries into a database when the back button is pressed. Basically, you want to control the back button by calling the following three functions during the execution of the scripts in your application. In what order exactly to call the functions (see questions above) is not clear from the tutorial.

All forwards movement is performed by using my scriptNext function. This is called within the current script in order to activate the new script.

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 

When any script has finished its processing it terminates by calling my scriptPrevious function. This will drop the current script from the end of the stack array and reactivate the previous script in the array.

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 

Whenever a script is activated, which can be either through the scriptNext or scriptPrevious functions, or because of the BACK button in the browser, it will call the following function to verify that it is the current script according to the contents of the program stack and take appropriate action if it is not.

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 

The action taken depends on whether the current script exists within the program stack or not. There are three possibilities:

  • The current script is not in the $page_stack array, in which case it is not allowed to continue. Instead it is replaced by the script which is at the end of the array.
  • The current script is in the $page_stack array, but it is not the last entry. In this case all following entries in the array are removed.
  • The current script is the last entry in the $page_stack array. This is the expected situation. Drinks all round!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:56:50+00:00Added an answer on May 10, 2026 at 11:56 pm

    That is a good discussion but more to the point you should be looking into Post Redirect Get (PRG) also known as ‘Get after Post.’

    http://www.theserverside.com/patterns/thread.tss?thread_id=20936

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is so basic that I'm almost embarrassed to ask it, but it's
Ever since I started programming this question has been annoying me, not where is
Ever wonder what wikipedia's database schema looks like? I recently read this thread from
Ever notice that, when you're scrolling an overflowed div or textarea with a mousewheel,
Ever since I added this async request, I'm getting an xcode error of Sending
Ever since I ported my game to Xbox with XNA the code that's supposed
Ever noticed that when you go to maps.google.com and do a search (say, car
Okay, this is pretty weird. I made an app that listens for changes inside
Just stumbled upon time_nanosleep() and started to wonder, when would you ever want to
This morning I stumbled across a surprising number of page faults where I did

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.