Whats the best way to reload/redirect a page in PHP which completely removes all history/cache? Which headers should I use?
What happens:
On clicking a link, get-parameters is set and a script is executed. When finished, I want to redirect and reload the page without the get-parameters. At first, it looks like nothing has happened, but when pressing F5, the changes appear.
What I want:
Redirect and reload so the changes appear without pressing F5.
<?php
header('Cache-Control: no-store, private, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Expires: 0', false);
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header ('Pragma: no-cache');
header("Location: https://example.com", true, 302);
exit();
?>
header('Location: http://www.example.com/', true, 302);
exit;
Ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
edit:
This response is only cacheable if indicated by a Cache-Control or Expires header field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With