首页 > 解决方案 > 如果用户登录 php,导航栏按钮排序

问题描述

嗨谢谢你帮助我我有一个导航栏和登录和注册按钮如果用户登录我想隐藏这些按钮我正在用 PHP 编写请帮助我

这些是我的导航栏和登录信息代码

<header class="navbar navbar-expand-lg  bg-gradient-default p-2 navbar-expand navbar-dark flex-row align-items-md-center ct-navbar bg-primary py-2">
        <a class="navbar-brand text-white" href="/"><img style="width:150px; height: 60px;" src="arodanalandscape.png" class="radius-10 shadow-sm"
                width="100"></a>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
  
</div>

                                <!--  <a style="font-family:'Droid-Arabic-Kufi';" href="team.php" class="btn btn-secondary my-2 my-sm-0"><i
                        class="fal fa-terminal ml-2"></i>تیمەکەمان</a>-->
                              

                              <a style="font-family:'Droid-Arabic-Kufi';"  href="login-user.php" class="btn btn-gradient-warning btn-round my-2  my-sm-0 text-white"><i
                        class="fal fa-sign-in-alt ml-2"></i> چونەژورەوە </a>

<a style="font-family:'Droid-Arabic-Kufi';" href="signup-user.php" class="btn btn-info mr-3 my-2 my-sm-0"><i
                        class="fal fa-user-plus ml-2"></i> خۆتۆمارکردن</a>

                        
<div class="dropdown ">
  <button style="font-family: 'Montserrat', sans-serif;" class="btn  btn-gradient-secondary  my-2 my-sm-0" type="button" id="multiDropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"  /> <i class="fas fa-cogs"></i> <strong class="center">  <?php echo $fetch_info['name'] ?>  <img style="width:40px; height:40px;" class="img-fluid rounded shadow card-img-top"   src= <?php echo $fetch_info['picture'] ?>>
   
  <div class="ripple-container mr-3"></div></button>
  <div class="dropdown-menu" aria-labelledby="multiDropdownMenu">
  <a style="background-color: #e63946; " class="btn-danger text-white dropdown-item mr-3" href="logout-user.php">Logout</a>
  <a style="background-color: #457b9d; "  class="text-white dropdown-item mr-3" href="profile-user.php">Profile</a>
    </div>
  </div>
</div>


                      <!--  <a href="" class=" btn  btn-success  my-2 my-sm-0  "><i class="fas fa-user"></i>  <strong class="center">  <?php echo $fetch_info['name'] ?>  <img style="width:40px; height:40px;" class="rounded-circle card-img-top"   src= <?php echo $fetch_info['picture'] ?> >  </a>
    -->

    </nav>

</header>

这是我的登录代码

 require_once "controllerUserData.php"; $email = $_SESSION['email']; $password = $_SESSION['password']; if($email != false && $password != false){
    $sql = "SELECT * FROM usertable WHERE email = '$email'";
    $run_Sql = mysqli_query($con, $sql);
    if($run_Sql){
        $fetch_info = mysqli_fetch_assoc($run_Sql);
        $status = $fetch_info['status'];
        $code = $fetch_info['code'];
        if($status == "verified"){
            if($code != 0){
                header('Location: reset-code.php');
            }
        }else{
            header('Location: user-otp.php');
        }
    } }else{
    header('Location: login-user.php'); } ?>

标签: phpnavbar

解决方案


代替...

<a style="font-family:'Droid-Arabic-Kufi';"  href="login-user.php" class="btn btn-gradient-warning btn-round my-2  my-sm-0 text-white"><i
                        class="fal fa-sign-in-alt ml-2"></i> چونەژورەوە </a>

<a style="font-family:'Droid-Arabic-Kufi';" href="signup-user.php" class="btn btn-info mr-3 my-2 my-sm-0"><i
                        class="fal fa-user-plus ml-2"></i> خۆتۆمارکردن</a>

和...

假设您在用户已经登录的情况下$loggedon设置了一个变量TRUE

<?php
if(!$loggedon){
    echo <<<EOT
        <a style="font-family:'Droid-Arabic-Kufi';"  href="login-user.php" class="btn btn-gradient-warning btn-round my-2  my-sm-0 text-white"><i
                    class="fal fa-sign-in-alt ml-2"></i> چونەژورەوە </a>
        <a style="font-family:'Droid-Arabic-Kufi';" href="signup-user.php" class="btn btn-info mr-3 my-2 my-sm-0"><i
                    class="fal fa-user-plus ml-2"></i> خۆتۆمارکردن</a>';
    EOT;
}
?>

推荐阅读