I am working on a project for the university. To make it clear. I have seperated all my sites and site section. Therefore i have a header.php.
So, in the header.php i have a normal nav with an ul and some li. The last li changes its value depends if the user is logged in or not.
If he is logged in, an ul with 3lis which containing an a-tag will be inserted. The Ul should be dropbox and the last li in this ul is to logout.
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href="index.php">Home</a>
</li>
<li>
<a class="page-scroll" href="index.php?url=order">Order</a>
</li>
<?php if($logged){
?>
<a class="page-scroll" data-toggle="dropdown"><img src="img/stuff/user_icon.png" alt="user_icon" width="40"/></a>
<ul class="dropdown-menu">
<li><a href="index.php?url=user_orders">My Orders</a></li>
<li><a href="index.php?url=logout">Logout</a></li>
</ul>
<?php }else {?>
<li> <a class="page-scroll" href="#" id="login">Login</a>
<?php }?>
</li>
</ul>
So now to my problem. Everything is working fine, except when i am trying to logout. My logout.php looks like that:
<?php
session_destroy();
header("location: index.php");
?>
The i get the error that the Headers have already been send and its referring to the last line of my header.php.
I have looked to the code and found out that if i remove this part
<a href="index.php?url=user_orders">My Orders</a>
the headers is working. But with it i am getting an error. Why is it like that and how can i solve that? I also want the other link to be displayed