When I use tabs to indent my HTML/PHP code in the file to make it more readable and nice formatted then I encounter strange issue of "Cannot modify header information - headers already sent" in PHP. When I undo indentation then everything seems to be OK. Any idea how's that? Here's my small snippet of code for which I am facing this strange issue:
<ul>
<li><a href="<?php echo BASE_URL; ?>" <?php if(basename($_SERVER['PHP_SELF']) == "index.php") echo "class='active'"; ?>>Home</a></li>
<li><a href="posts" <?php if(get_page_title() == "Posts") echo "class='active'"; ?>>Blog</a></li>
<li><a href="gallery" <?php if(get_page_title() == "Gallery") echo "class='active'"; ?>>Gallery</a></li>
</ul>
EDIT
My problem is due to indentation which is allowed in source code for well formatting. Why this question is put on duplicate?
When I put my code in following way:
<ul>
<li><a href="<?php echo BASE_URL; ?>" <?php if(basename($_SERVER['PHP_SELF']) == "index.php") echo "class='active'"; ?>>Home</a></li>
<li><a href="posts" <?php if(get_page_title() == "Posts") echo "class='active'"; ?>>Blog</a></li>
<li><a href="gallery" <?php if(get_page_title() == "Gallery") echo "class='active'"; ?>>Gallery</a></li>
<li><a href="contact" <?php if($title == "Contact") echo "class='active'"; ?>>Contact</a></li>
</ul>
The it does work, but when I format above code in following style:
<ul>
<li><a href="<?php echo BASE_URL; ?>" <?php if(basename($_SERVER['PHP_SELF']) == "index.php") echo "class='active'"; ?>>Home</a></li>
<li><a href="posts" <?php if(get_page_title() == "Posts") echo "class='active'"; ?>>Blog</a></li>
<li><a href="gallery" <?php if(get_page_title() == "Gallery") echo "class='active'"; ?>>Gallery</a></li>
<li><a href="contact" <?php if($title == "Contact") echo "class='active'"; ?>>Contact</a></li>
</ul>
Then it stops working. Strange!!! isn't it?
On line number 8 in functions.php file, I have a function which has following:
header("Location: " . $url);
// Page redirection
function redirect_to($url)
{
if(isset($url) && $url != "")
{
header("Location: " . $url);
exit();
}
}
NOTE
Note that if I remove my navigation code then error is automatically gone away.