How to hide/connect items in the navbar while logged in

Asked

Viewed 25 times

-1

I am making a login system is already working normally the problem is that I do not know how to change the navbar while the user is logged in:

Codigo Index:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redfield</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <header>
        <nav>    
            <img class="logo"src="AA.png" alt="">
            <ul class="navlist">
                <a href="index.php" style="text-decoration: none;">Home</a>
                <a href="/" style="text-decoration: none;">Launcher  </a>
                <a href="/" style="text-decoration: none;">Social Media  </a>
                <a href="login.php" style="text-decoration: none;">Login</a>
                </div>
            </ul>
        </nav>
    </header>
    <main>
        
    </main>
</body>
</html>

Verification code:

session_start();
include("checking.php");

if(empty($_POST['usuario']) || empty($_POST['password'])){
    header('Location: login.php');
    exit();
}

$usuario = mysqli_real_escape_string($conexao ,$_POST['usuario']);
$senha = mysqli_real_escape_string($conexao ,$_POST['password']);

$query = "select usuario_id from usuario where usuario = '{$usuario}' and senha = md5('{$senha}')";
$result = mysqli_query($conexao, $query);

$row = mysqli_num_rows($result);

if($row == 1){
    $_SESSION['usuario'] = $usuario;
    header('Location: painel.php');
    exit();
    
}else{
    header('Location: login.php');
    exit();
}

1 answer

0

Depending on the session (if any), you call a different PHP file in your painel.php.
I’ll give names just to illustrate: navbarNaoLogado.php and navbarLogado.php


PHP:
if(isset($_SESSION['usuario']) and !empty($_SESSION['usuario'])) {
    include_once(__DIR__.'/navbarLogado.php');
} else {
    include_once(__DIR__.'/navbarNaoLogado.php');
}

That is, if the $_SESSION['usuario'] exist and is not empty, will be called the navbarLogado.php, otherwise, will be called the navbarNaoLogado.php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.