title: Why show an error header already sent?
body: <pre><code>    &lt;table&gt;
       &lt;tr&gt;
        &lt;td width="30"&gt;&lt;/td&gt;
        &lt;td&gt;&lt;img src="Images/logo.jpg" width="100" height="100" /&gt;
        &lt;td&gt;&lt;td&gt;&lt;h2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Kunal Structures (India) Pvt. Ltd.&lt;/h2&gt;&lt;/td&gt;
       &lt;/tr&gt;
      &lt;/table&gt;
      &lt;?php
  
      if(!isset($_SESSION['user_id']))
      {
          header("location:http://127.0.0.1/New%20folder/KSIPL1.10/KSIPL/index.php");
      }
      else 
      {
          $now = time(); // checking the time now when home page starts
          if($now &gt; $_SESSION['expire'])
          {
                  header("location: http://127.0.0.1/KSIPL1.10/KSIPL/index.php"); 
                  echo "Session Expired !"." &lt;a href='http://127.0.0.1/New%20folder/KSIPL1.10/KSIPL/index.php'&gt;"." &lt;h1&gt; ".
                  "Login again"." &lt;/h1&gt;"."&lt;/a&gt;";
  
                  session_destroy();
          }
          else
          {
              $qry = mysql_query("SELECT * FROM user_main WHERE user_id=".$_SESSION['user_id']."");
              $loguser=mysql_fetch_assoc($qry);
  
              ?&gt;
                  &lt;table class="headerinfo" align="right"&gt;
                  &lt;tr&gt;
                  &lt;td&gt;You are &lt;span style="color:#40B3BA;"&gt;&lt;?php echo $loguser['user_name']; ?&gt;&lt;/span&gt;,&lt;/td&gt;
                  &lt;td&gt;&lt;a style="color:#f5f5f5; text-decoration:none;" href="logout.php"&gt;&lt;b&gt;Logout&lt;/b&gt;&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;br/&gt;
  &lt;/div&gt;  
              &lt;?php
  
              if($loguser['user_type'] == "Administrator") //Custom Menubar for Administrator
              {
                  ?&gt;
                  &lt;div class="row-fluid"&gt;
                      &lt;div class="navbar"&gt;
                      &lt;div class="navbar-inner"&gt;
                          &lt;a class="brand" href="#"&gt;&lt;/a&gt;
                          &lt;ul class="nav"&gt;
                          &lt;li&gt;&lt;a href=""&gt;Home&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href=""&gt;Documents&lt;/a&gt;&lt;/li&gt;
  
                          &lt;/ul&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;?php
              }
          }
      }
  </code></pre>
  
  <p>why it shows me an error like header already sent and do not redirect to given path.
  When session_['expire'] condition becomes true it shoud be move to <code>index.php</code> file but it not happen because of the header error.
  How can i solve this problem. Is there any solution for avoiding header error.</p>