title: I cannot start sessions for different user roles and restrict folders for logged out users
body: <p>I am using a login script and I am trying to get my head around sessions with not much luck.</p>
  <p>When the user logs in I want them redirecting to the relevant folder, here is my login script</p>
  <pre><code>  if (isset($_POST['btnLogOn'])) {  
          $email     = !empty($_POST['email']) ? trim($_POST['email']) : null;
          $password = !empty($_POST['password']) ? $_POST['password'] : null;   
          $db=DB();
          $sql = &quot;SELECT  * FROM users WHERE  email = ? LIMIT 1&quot;;
          $stat = $db-&gt;prepare($sql);
          $stat-&gt;bindParam(1, $email, PDO::PARAM_STR);
          $stat-&gt;execute();
          $row = $stat-&gt;fetch();
          if ($row &amp;&amp; password_verify($password, $row['password'])) { 
              if (isset($_POST['remember'])) {
                  setcookie('email', $email, time() + 60 * 60 * 7);
                  setcookie('password', $password, time() + 60 * 60 * 7);
              }
              {
            $_SESSION['user_session'] = $row['user_id'];
            $_SESSION['user_role'] = $row['role'];
            switch($_SESSION['user_role']){
               case 'Admin':
                   $_SESSION['user_role'];
                   header( 'Location: admin');
                   break;
               case 'Advisor':
                   $_SESSION['user_role'] ;
                   header( 'Location: advisor');
                   break;
                case 'Tech':
                   $_SESSION['user_role'] ;
                   header( 'Location: tech');
                   break; 
                  case 'User':
                   $_SESSION['user_role'];
                    // redirect to admin
                   header( 'Location: dashboard');
                   break; 
                  }
  </code></pre>
  <p>I am not sure if the above code is correct and I am really struggling in what code to write in the header of each &quot;named&quot; folders.</p>
  <p>I have tried a lot of messing with code below in the seperate headers  but it either keeps refreshing to the ../index.php or it lets me open the folder whether i am logged in or not</p>
  <pre><code>            session_start();
           $_SESSION['user_session'] = $row['user_id'];
            $_SESSION['user_role'] = $row['role'];
              if(empty($_SESSION['user_role'])){
              header('Location: ../index.php');
              }
  </code></pre>
  <p>What I want to happen when the user logs on the role determines which folder to open and if no one is logged on they cannot open the folder</p>
  <p>Hope that makes sense</p>
  <p>Thanks
  Molly</p>