I want to save my website header into $nav. I got all of it working, except for the part where I want to echo the username of the user.
I've tried multiple things, such as setting $_SESSION['username']; to $user and then try to echo $user into $nav, but this didn't work.
I also tried to just echo $_SESSION['username'], but it is not possible to use ''s as it will cause interruptions.
I am sure $_SESSION['username']; is set because I used var_dump($_SESSION); to check what things were set.
Output of var_dump($_SESSION);: array(3) { ["success"]=> string(21) "You are now logged in" ["rank"]=> string(1) "3" ["username"]=> string(5) "admin" }
My current code:
$user = $_SESSION['username'];
$nav = '<li><a href="index.php" class="kk" style="color: white;"><font color="white"><i class="fas fa-home"></i><b> Home</b></font></a></li>
<li style="float:right"><a href="/index.php" class="header" style="color: white;"><i class="fas fa-user"></i><b><?php echo $user; ?></b></a></li>';
I expect the output of $_SESSION['username'], but it doesn't give me any output at all.