Force Page To Reload From Server Instead Of Load The Cached Version
I have webpage A. The user clicks on a form to submit data, and it takes him to webpage B. When he clicks the back button, I need webpage A to be refreshed from the server, rather
Solution 1:
OK try this instead:
<?phpif(!session_id()) {
@session_start();
}
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
if(isset($_SESSION['form_submitted'])) {
unset($_SESSION['form_submitted']);
header('Location: ?' . uniqid());
#header('Refresh: 0');
}
?>
You will need to set $_SESSION['form_submitted'] = true on page 2.
Solution 2:
Try with all three:
<metahttp-equiv="cache-control"content="no-cache"><!-- tells browser not to cache --><metahttp-equiv="expires"content="0"><!-- says that the cache expires 'now' --><metahttp-equiv="pragma"content="no-cache"><!-- says not to use cached stuff, if there is any -->
Solution 3:
<?php
session_start();
if(isset($_SESSION['reloadPage'])) {
unset($_SESSION['reloadPage']);
//no outputting code above header
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Location: http://www.mypage.com/");
}
?>
Solution 4:
I know this is old question and already have the answer (that not refreshing from the server). So I would like to share a solution using jQuery.
$('#back-button').click(function(){
setTimeout(location.reload(true), 1000);
});
Explanation:
As you click the back button, the setTimeout
will triggered after 1 second (1000 milliseconds). Then, the page will reload from the server as the parameter inside the reload
is true
.
If you put true
inside the reload
it will reload from the server while if you put false
it will reload from the cache. Source w3schools.
Solution 5:
Your JavaScript should be...
window.location = "/****/****/*****.php"
I think that should fix your loop.
Post a Comment for "Force Page To Reload From Server Instead Of Load The Cached Version"