title: I am getting Notice: Undefined index: loggedin in when using SESSION
body: <p>When a user is successfully authenticated, s/he is either redirected to register.php if the user has not yet signed up for training.</p>
  
  <p>If the user has already signed up for training, s/he is redirected to registered.php to view/modify his or her training classes.</p>
  
  <p>So far, this works fine.</p>
  
  <p>Problem is if user attempts to go directly to register.php or registered.php, s/he gets into any of the web pages without logging in first.</p>
  
  <p>This is what I am trying to prevent but I keep getting the following error message:</p>
  
  <pre><code>Notice: Undefined index: loggedin in .... on line 3
   Please log in first to see this page 
  </code></pre>
  
  <p>Here is what I am using so far and thanks for your help.</p>
  
  <pre><code>//login.php
  
   $user = trim($_POST['user']);
   $pass = trim($_POST['pass']);
  
       // hash to sanitize the input further
      $pass = md5($pass);
  
     $tSQL = "SELECT u.empl_first, u.username FROM users u inner join Training t on u.Employee_Id = t.Employee_ID WHERE USERNAME = ?
      and PASSWORD = ? ";
  
      $params = array($user, $pass, $params);
      $sqll = sqlsrv_query($con, $tSQL);
  
  if ($objResult = sqlsrv_fetch_array($sqll, SQLSRV_FETCH_ASSOC)) {
      $firstname = $objResult["empl_first"];
      $_SESSION["firstname"] = $objResult["empl_first"];
      $_SESSION['loggedin'] = true;
      $_SESSION['username'] = $user;
      header('location:registered.php');
    }
    else
      header("location:register.php?user='".ms_escape_string($user)."'&amp;pass='".ms_escape_string($pass)."' ");
  
  sqlsrv_close($con);
  
  ?&gt;
  </code></pre>
  
  <p>//register.php</p>
  
  <pre><code>&lt;?php
  session_start();
  if (!isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] != true) {
      echo "Please log in first to see this page";
  }
  </code></pre>