The problem is that when logging into the site, the error disappears (since the session is uid). If the user is not authorized, then he writes everywhere Notice: Undefined index: uid in ...

how to fix this error?

class User { public $con; public function __construct() { $data = new Basic; $db = $data->getConnection(); $this->con = $db; } public function IsAdmin() { $stmt = $this->con->prepare("SELECT who FROM users WHERE uid = :uid"); $stmt -> execute(array(':uid' => $_SESSION['uid'])); $who = $stmt -> fetchColumn(0); if ($who == 2) { return true; } else { return false; } } public function is_loggedin() { if(isset($_SESSION['uid'])) { return true; } } 

}

in header:

 <?php if ($user -> IsAdmin()) {?> Видят только администраторы <?php } ?> 
  • Well, that's right, if the user is not authorized, then where does $ _SESSION ['uid'] come from. - Alexander Semikashev 2:51 pm
  • How to make sure that it does not show this error? Notice: Undefined index: uid in ... User.php on line 15 - BAFF
  • check for $ _SESSION ['uid'] - Alexander Semikashev
  • check isset? - BAFF
  • It is possible and through isset - Alexander Semikashev

0