Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member medlington's Avatar
    Join Date
    Nov 2005
    Location
    Sheffield, UK
    Posts
    377
    Member #
    11968
    Liked
    4 times

    Are script pages triggered when back button is pressed?

    Hi,

    I have created an online booking system for a nighclub and a couple of times a year something strange happens and one of the features of the system gets triggered twice. I have a feeling that this is because the user is either pressing submit several times or that they are pressing back on their browser and it is triggering the script from the last page again.

    I have tried to stop this by adding a session variable to each page that is the url of that page, everytime a new page is reached the session variable is updated with the new URL of that page. When the user completes that page and submits it it goes to my script where the script checks to see if the data is coming from the correct page by checking the value of the session var. If the var doesnt match what is expected it throws the user to the URL stored in the session var. So I thought if the user submits a page and then clicks back they will just be redirected to the page they were on rather than triggering the script again.

    however when I have tested this and I click Back it just goes to the last page that was displayed and seems to bypass the script page. Is this correct? does the Back button only go back to the last page with HTML on to be displayed or does it go back to the script but I have just done it wrong?

    Thanks

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    It could be either. There's no way for PHP to know when the back button is pressed on a browser, so that means the page will sit there as it was at the time until requested again.

    Whatever the feature is, you'll need to run a query to see if it's been triggered by that user, and if it has, don't retrigger it. I'm guessing it's something that writes to database, which should be fairly simple...check for the presence of an existing record that matches the user and any other parameters, and only insert the new one if it doesn't match.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Senior Member medlington's Avatar
    Join Date
    Nov 2005
    Location
    Sheffield, UK
    Posts
    377
    Member #
    11968
    Liked
    4 times
    Yep it writes a new callback request to the database and sets the last callback to 'complete' however sometimes it initiates the new callback but doesnt set the last one to 'complete' either that or it is writing 2 new callback requests to the DB but the strange thing is the 2 requests are not identical. Thats why I figured it was running the script again when the user had pressed back but this time without the variables posted from the previous page. After thinking about this again though I think it would sent the same post variables to the script if you hit the back button anyway.

    I guess I could just put in a script that checked if a callback had been written in the last 2 or 3 minutes with the same booking reference number and if so dont do it again but then the issue could be that it has written the non complete callback first and then would refuse to create the correct one for a few minutes. Guess I just got to test it a few times.

    Thanks

  5. #4
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Session Variables can save you a lot of grief and can cause grief, unless you know when to flush or kill those variables...

    any time you use a session variable for a "single" transaction, the last step, is to kill those variables to keep from making multiple transactions.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:22 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com