猿问

导航栏出现两次不尊重php if语句

我试图根据用户是否登录来更改导航栏。最终还要检查用户是否是管理员,并根据这些条件使用不同的列表项。


问题是因为我的条件是在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");


  }


?>


智慧大石
浏览 134回答 1
1回答

暮色呼如

您的index.html页面未解析为php。将扩展名更改为.php或更改配置以也解析html文件。
随时随地看视频慕课网APP
我要回答