title: How can I find out if my user has an admin permission?
body: <p>I'm currently coding a blog to get experience with php in which I can log in. In the table:</p>
  
  <pre><code>user( id, username, password, permission)
  </code></pre>
  
  <p>there is one user that has the permission "admin", every other user has the permission "normal".</p>
  
  <p>I want that only an admin can edit posts, so I need to find out what permission the currently logged in user has. I tried to do it with Sessions, but somehow I didn't manage to get it work. </p>
  
  <p>This is the query in the <code>UserRepository.php</code> in which I interact with the db</p>
  
  <pre><code>public function isAdmin($username)
  {
    $table = $this-&gt;getTableName();
    $model = $this-&gt;getModelName();
  
    $stmt = $this-&gt;pdo-&gt;prepare("SELECT `permission` FROM `{$table}` WHERE username = :username");
    $stmt-&gt;execute(['username' =&gt; $username]);
  
    $stmt-&gt;setFetchMode(PDO::FETCH_CLASS, $model);
    $isAdmin = $stmt-&gt;fetch(PDO::FETCH_CLASS);
  
    return $isAdmin;
  } 
  </code></pre>
  
  <p>Here is the part of a function from the <code>LoginService.php</code> in which I call the upper function in the repository:</p>
  
  <pre><code>public function attempt($username, $password)
  {
    $user = $this-&gt;userRepository-&gt;findByUsername($username);
  
    if (password_verify($password, $user-&gt;password)) { 
    if ($this-&gt;userRepository-&gt;isAdmin($user-&gt;username) == "admin") {
      $_SESSION['admin'] = "admin";
    }
    $_SESSION['login'] = $user-&gt;username;            
    session_regenerate_id(true);                    
    return true;                                      
  }
  </code></pre>
  
  <p>This is a part of the <code>__construct</code> in the <code>PostsAdminController.php</code> in which I'm trying to get the value of the permission of the logged in user and save it into the session if it is "admin" and not "normal":</p>
  
  <pre><code>$username = $_SESSION['login'];
  $permission = $this-&gt;userRepository-&gt;isAdmin($username);
  
  if ($permission == "admin") {
    $_SESSION['admin'] = $permission;
  </code></pre>
  
  <p>I also have a part of the header, because for admins there is a different navigation as for normal user. </p>
  
  <pre><code>&lt;?php if(!empty ($_SESSION['login'])):?&gt;
    &lt;div class="logged-in-user"&gt;
      &lt;div class="dropdown"&gt;
        &lt;button class="dropbtn"&gt;
          &lt;a href="http://localhost:8888/blog/public/index.php/dashboard"&gt;
            &lt;?php echo e($_SESSION['login']);?&gt;
          &lt;/a&gt;
        &lt;/button&gt;
      &lt;div class="dropdown-content"&gt;
        &lt;?php if ($_SESSION['admin'] == "admin"): ?&gt;
          &lt;a href="http://localhost:8888/blog/public/index.php/dashboard"&gt;
            dashboard
          &lt;/a&gt;
  </code></pre>
  
  <p>This won't give me the dashboard for both, the admin and the normal user. But if I ask if it's set:</p>
  
  <pre><code>&lt;?php if (isset($_SESSION['admin'])): ?&gt;
  </code></pre>
  
  <p>Then it shows the dashboard in the dropdown-navigation for both again...</p>
  
  <p><strong>I don't know why it doesn't work, so how do I correctly find out the permission of the logged in user and show them different things based on their permission?</strong></p>