If you are going to do a redirect, the PHP code block must come before anything that outputs to the browser - that includes
echo
, HTML (or even spaces or a BOM) outside of
<?php ... ?>
blocks and any other functions that cause output:
<?php
if($something) {
header('Location: http://other.url');
exit;
}
?>
<!DOCTYPE html>
<head>
... rest of page ...