导航栏出现两次不符合 php if 语句

Nav bar appears twice doesn't respect php if statement

我正在尝试根据用户是否已登录来更改我的导航栏。最终还会检查用户是否是管理员,并根据这些条件具有不同的列表项。

问题是因为我的条件是 PHP 它似乎不遵守 if 语句,并且在加载页面时显示两个 ul。

我的页面顶部有一个会话开始,因此应该存储 "loggedin" 的值。

<header>
<div class="container">
    <div class="Logo">
        <img src="./images/LogoSmall.png" width="60px" height="60px" alt="Logo">
        <h2> Quality Speakers Global </h2>
    </div>
    <div>
    <nav>
    <?php
        if($_SESSION["loggedin"] == "yes"){
        ?>
        <ul>
            <li class="current"><a href="Index.html">Home</a></li>
            <li><a href="Register.html">Login/Register</a></li>
            <li><a href="Slideshow.html">Products</a></li>
            <li><a href="Report.html">Report</a></li>
            <li><a href="userpage.php">My Account</a></li>
        </ul>
    <?php } else{?>
        <ul>
            <li class="current"><a href="Index.html">Home</a></li>
            <li><a href="Register.html">Login/Register</a></li>
            <li><a href="Slideshow.html">Products</a></li>
            <li><a href="Report.html">Report</a></li>
        </ul>       
    <?php       
    }
    ?>

    </nav>
</div>
</header>

我想要的是根据条件只显示ul

这是我的 php 登录码:

<?php

  session_start();

  $con = mysqli_connect('localhost','root','pass1','accounts');

  if(isset($_POST["UsernameLogin"])) {

      $Logusername = $_POST['UsernameLogin']; 
  }

  if(isset($_POST["PasswordLogin"])) {

      $Logpassword = $_POST['PasswordLogin'];
  }

  $query = " select * from users where username = '$Logusername' && password = '$Logpassword'";

  $result = mysqli_query($con, $query);

  $row = mysqli_fetch_assoc($result);

  $num = mysqli_num_rows($result);

  if($num == 1) {
      $_SESSION["username"] = $Logusername;
      $_SESSION["level"] = $row["usertype"];
      $_SESSION["loggedin"] = 'yes';

      if($_SESSION["level"] == "admin") {

          header('location:AccountsPage.php');
      } else {

          header('location:userpage.php');
      }   
  } else {
    header("Location: Index.html");

  }

?>

您的 index.html 页面未被解析为 php。将扩展名更改为 .php 或更改配置以同时解析 html 个文件。