duaiwu8385 2019-04-19 18:27
浏览 48
已采纳

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

I am trying to change my navigation bar depending on whether the user has signed in. Eventually also checking whether the user is an admin or not and having different list items depending on these conditions.

The issue is since my condition is in PHP it doesn't seem to respect the if statement and when the page is loaded both ul are shown.

I have a session start at the top of my page so the value of "loggedin" should be stored.

<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>

What i want is to only show the ul depending on the condition

here is my php login code:

<?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");

  }

?>
  • 写回答

1条回答 默认 最新

  • douyakan8924 2019-04-19 18:46
    关注

    Your index.html page is not being parsed as php. Change the extension to .php or change configuration to also parse html files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)