title: Redirect fails in PHP
body: <p>Here is a piece of code in PHP written in a separate file called <em>core.php</em> and this is included in <em>register.php</em></p>
  
  <pre><code>if(($retuserkey = $this-&gt;dbcontroller-&gt;dbregister($email, $contact)) &gt; 0){  
      //if user was successfuly registered send an email where he can activate his account!
      $this-&gt;mailer-&gt;sendForReg($email,$hash,$flname);
  
      echo "&lt;script&gt;alert('An activation link is sent to your email id. Please check you spam folder too. Please follow the link to complete the registration.'); window.location = './registersuccess.php';&lt;/script&gt;";
  
      echo '&lt;META HTTP-EQUIV="Refresh" Content="0; URL=http://www.websiteaddress.com/registersuccess.php"&gt;'; 
      $url = "http://www.websiteaddress.com/registersuccess.php";
      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 '&lt;script type="text/javascript"&gt;';
          echo 'window.location.href="'.$url.'";';
          echo '&lt;/script&gt;';
      }
  
      mail("emailaddress@gmail.com","Registration $retuserkey",$email,"Subject");
  }
  </code></pre>
  
  <p>Emails are sent both before and after the redirect. Both the emails are received but the redirect fails.</p>
  
  <p>What am I doing wrong?</p>