Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way redirect/reload pages in PHP

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.

like image 856
jorgen Avatar asked Oct 15 '09 12:10

jorgen


2 Answers

<?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();
?>
like image 56
warfish Avatar answered Nov 05 '22 12:11

warfish


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.

like image 22
Ismael Avatar answered Nov 05 '22 13:11

Ismael