title: Best redirect methods?
body: <p>In a PHP file when I need to redirect a user and headers are already sent so I can not use php's header function, in this case which is the best method to redirect a user?</p>
  
  <p>Fastest and most reliable method regardless of the users browser brand?</p>
  
  <pre><code>echo '&lt;script type="text/javascript"&gt;window.top.location="http://localhost/";&lt;/script&gt;';
  
  // OR
  
  echo '&lt;meta http-equiv="refresh" content="0;url=' .$location. '"&gt;';
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is my end result code I am using now, if headers are already sent where I cannot redirect to the homepage, I just bring the homepage to me, so instead of including the body page, it will include my homepage and footer</p>
  
  <pre><code>function validlogin($url) {
      if (!isset($_SESSION['auto_id']) || ($_SESSION['auto_id']=='')) {
          $_SESSION['sess_login_msg'] = 'Please login';
          $_SESSION['backurl'] = $url;
          $temp = '';
          if (headers_sent() === false){
              header("Location: /");
              exit();
          }else{
              //header is already sent so we will just bring the homepage to us instead of going to it!!!
              include 'mainbody.inc.php';
              include 'footer.inc.php';
              exit();
          }
      }
  }
  </code></pre>