0

In Safari 10.1.1 the browser's back button does not reload the target page, so $_SERVER['SCRIPT_NAME'] is not changed.

Is there a way to reload the target page when the browser's back button is pressed. I tried the following:

header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.

This does not work.

Background: I try to build a reliable page history in PHP, but how can I, if the browser's back button does not trigger anything on the server?

Thank you!

Phantom
  • 638
  • 1
  • 7
  • 18
  • What's the purpose behind building a reliable page history? What are you trying to accomplish? You could do something with AJAX, I suppose, but *why*? Have you considered using JavaScript's History API for navigation? – ceejayoz Oct 17 '17 at 14:38
  • Thank you for your comment. I try to break it down: I have a start page and a second page. I move from the start page to the second page and back. If I enter the start page from the second page a different content (a different operation on the server) should be shown/triggered. What would be the right way to accomplish this? Thank you! – Phantom Oct 17 '17 at 14:58

1 Answers1

1

In your case the browser does not call the server AT ALL. In most cases the browsers will just show the "local/cached" version of the previous page and won't initiate a connection to the server.

You might find some javascript solutions here to force the reload : How to force reloading a page when using browser back button? or here How to refresh page on back button click?

The most relevant part being the use of the windows.performance object.

if(!!window.performance && window.performance.navigation.type === 2)
{
    window.location.reload();
}
Flunch
  • 816
  • 5
  • 17
  • Thank you very much. I thought some "no-cache" command (on PHP or HTML site) could stop the caching so the browser must initiate a connection to the server. Is there nothing like that? – Phantom Oct 17 '17 at 14:43
  • The headers example you provided is already good and there is nothing more you could add, so if the browser still keeps a cached version the JS is the only workaround. Did you apply thoose headers on every pages (the current and the "previous" before the previous was loaded) ? – Flunch Oct 17 '17 at 14:50
  • Yes, the header is applied to every page. Thank you! – Phantom Oct 17 '17 at 14:57