Index undefined when downgrade

Asked

Viewed 36 times

1

I did a test and put a way to identify when the user is logged in to the site, and this is working well. But when I get relaxed and go to the index, which is the page I put the code, the error appears

Notice: Undefined index: nivel in C: Program Files (x86) Easyphp-Devserver-14.1VC9 data localweb site tcc index.php on line 5

I wanted to know a way to get it out when it’s out, and only to show the message I put to the users who logged in. Code that I used

<?php
session_start();
include "php/conexao.php";

if($_SESSION['nivel'] == "admin" ||  $_SESSION['nivel']== "usuario"){ 
echo "oi logado";
}
?>

1 answer

0


You can use isset() to check if there is index 'level' in the session. This way it will not generate an error if it does not exist.

if(isset($_SESSION['nivel'])){ 
  echo "oi logado";
}
?>

  • Thank you, that’s right!!

  • Good!! You’re welcome!

Browser other questions tagged

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