best way redirect/reload pages in PHP best way redirect/reload pages in PHP php php

best way redirect/reload pages in PHP


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.


function redirect($url) {    if(!headers_sent()) {        //If headers not sent yet... then do php redirect        header('Location: '.$url);        exit;    } else {        //If headers are sent... do javascript redirect... if javascript disabled, do html redirect.        echo '<script type="text/javascript">';        echo 'window.location.href="'.$url.'";';        echo '</script>';        echo '<noscript>';        echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';        echo '</noscript>';        exit;    }}// How to use$url = "www.google.com";redirect($url);


The best way to reload a page and force it to be not taken from the cache will be to append a random id or timestamp to the end of the url as querystring. It makes the request unique each time.