Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    47
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Prevent dialogue re-displaying when back button is clicked

    I have created a form which works as required, on submission a modal dialogue displays based on a GET variable

    PHP Code:
    header("Location: index.php?feedback=feedback&thanks=$thanks");
        
    if(isset(
    $_GET['thanks']) && $_GET['thanks'] == 'Thanks'){        
    $thanks "<h2 class='thank'>Thank you!</h2><p>Your Feedback<br>is Appreciated!</p>";        
    }else{       
     
    $_GET['thanks'] = '';       
     
    $thanks =  '';                

    which contains a close button.

    Code:
    Close: function () {
                    $(this).dialog("close");
                    window.location.href="index.php?feedback=feedback";
                    
                }
    When the close button is clicked the page reloads an everything is fine.

    However if the browser back button is clicked the same confirmation dialogue re-displays.
    Because the thanks=$thanks variable is still part of the url.
    Is there a way to prevent this? Perhaps by clearing the GET varialble.
    Last edited by maxwell5; Feb 4th, 2019 at 10:07 PM.

  2. #2
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,329
    Thanks
    4
    Thanked 480 Times in 468 Posts
    Don't pass it in the URI or waste time with a header redirect, particularly if you're just redirecting to a common index.php. Just show it as part of the page that's processing the data. (which is probably ALSO an index.php, right? Possibly even the same index.php? So why redirect?)

    Though preventing "back" behaviors on stuff like this generally isn't even a "thing" you can do. Ever. Period. The best you can hope for is to add a random hash to your form and session, then invalidate it just to be certain it isn't accidentally resubmit.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •