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 } ?>