簡體   English   中英

導航欄出現兩次不尊重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文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM