best way redirect/reload pages in PHP

jorgen picture jorgen · Oct 15, 2009 · Viewed 53.5k times · Source

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.

Answer

Ismael picture Ismael · Oct 15, 2009
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.