Beginner PHP coder here
I am trying to use if statement to detect sessions, and by that changing the navigation bar from login to logout when logging in with the right username and password. I put the php script before the html but I still get the "Header already sent in" error. The Script:
<?php
session_start();
?>
<DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=main.css>
</head>
<body>
<div id="wrapper">
<nav>
<ul class="main_menu">
<li><a href="mainpage.html">Main page</a>
<li><a href="contact.html">Contact Us?</a>
<li><a href="aboutus.html">About Us</a>
<?php
if (isset($_SESSION['username'])){
echo "<li><a href="Logout.php">Logout</a>";
} else {
echo "<li><a href="Login.php">Login</a>";
}
?>
</ul>
</nav>
</div>
</body>
</html>
What am I doing wrong?