-1

I am looking for a solution to show different menu-bar to users as per their login status.

For example, if the user is not logged in , they will see the different menu-bar and once logged in they see the other.

I am able to attain this by making two different menu-bars and including them as per $_SESSION()

<?php 
        include('connection.php');  
        session_start();
        if($_SESSION["login"] != "login"){
            unset($_SESSION['login']);
            include('includes/header.php'); // menubar to display if not logged in.
        }else {
            include('includes/header-login.php'); // menubar to display when logged in.
        }
    ?>

This allows me to show different menu-bar as per the user login status, but the problem is that when the user ins not logged in and they access the page, they see this error

Notice: Undefined index: login in C:\xxx\htdocs\xxx\abc.php on line 34

So what can be the solution for same ?

1 Answers1

2

Instead of if(!$_SESSION["login"] == "yes")try the following as your condition check

if (isset($_SESSION['login'])) {
    // menubar to display when logged in.
}else{
    //menubar to display if not logged in.
}
Jamiul alam khan
  • 159
  • 1
  • 10