1

I'm working on an order form where the items to be ordered are set in a cookie. When the form is submitted, it is processed and it goes to a confirmation page with details of the order.

At the end of the confirmation page, the cookie is removed with jQuery $.removeCookie("cookie_name"); and the session is destroyed in PHP session_unset(); session_destroy();

If the user clicks the back button, the top of the order page looks to see if that cookie is present and if not, it skips the page and goes back to the starting point before any items were chosen.

if (!isset($_COOKIE["cookie_name"])) {
    header( 'Location: order.php' );
    exit;
}

Oh Chrome, this works just fine. On Safari, pressing the back button from the confirmation page stays on the page and shows all the items as if they were not ordered yet. However the cookie was destroyed. It is just displaying the page. How can I get Safari to realize that the cookie is actually gone? Refreshing the page clears it out and redirects as it should. I tried setting the a cache busting variable on the javascript file and tried setting the meta tag to not cache the whole page but it appears to be related to Safari.

Thanks!

Wes
  • 866
  • 10
  • 19
  • 1
    Safari is fun, it likes to give you the precise state of your previous page regardless of what the header, cookies, or cache says. Press F5 and the cookie should be obeyed. Probably a security feature so that viruses can't force you into an infinite loop of staying on the same page. – MonkeyZeus Mar 23 '17 at 18:52
  • 1
    http://stackoverflow.com/questions/10511893/prevent-back-button-after-logout – MonkeyZeus Mar 23 '17 at 18:56
  • http://drupal.stackexchange.com/questions/27358/after-logging-off-a-user-is-able-to-see-the-pages-by-pressing-back-button-of-th – MonkeyZeus Mar 23 '17 at 18:56
  • @MonkeyZeus Thank you! That did the trick. The code that worked for me was: `$(window).bind("pageshow", function(event) { if (event.originalEvent.persisted) { window.location.reload() } });` – Wes Mar 23 '17 at 19:27
  • Nice! Did you get your answer from http://stackoverflow.com/a/15497411/2191572 ? Because I do not see it in the links I provided lol. Anyways, feel free to add an answer to your own question so that future visitors can find the solution easier. Also, you should probably cite that answer within your answer. If not then this question should technically be deleted or marked as duplicate. Anyways, nice! Also, take note of the iPad comments sprinkled across the answers; I assume it applies to iOS in general. – MonkeyZeus Mar 23 '17 at 19:56

0 Answers0