title: How to Check either Session is Set or Not in Codeigniter?
body: <p>I know how to create session in core PHP, and I have understand how to do this in codeigniter, but I am unable to understand how to check, if the session is set or not? I have tried to check this through View but it always give me the meesage <code>Please Login</code>. </p>
  
  <p>Kindly tell me how can I check whether the session is Set or not Set </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>if ($user_type=='Student')
  {
    if ($LoginData=   $this-&gt;loginmodel-&gt;studentLogin($username,$password))
    {
      foreach($LoginData as $UserId)
      {
        $currentId= $UserId-&gt;StudentId;
      }
      //[[session]]
  
      $data['students_data']=         $this-&gt;loginmodel-&gt;student_profile($currentId);
  
      $this-&gt;session-&gt;userdata('$data');
  
      $this-&gt;load-&gt;view('students',$data);
    }
    else
    { 
    //$data['message']= array('Invalid Username or Password');
      $this-&gt;load-&gt;view('Login');
      echo "Invalid Username or Password";
    }
  }
  elseif ($user_type=="Faculty")
  {
    if($data['faculty_data']=$this-&gt;loginmodel-&gt;faculty_admin($username, $password))
    {
      $this-&gt;session-&gt;userdata('$data');
  
      $this-&gt;load-&gt;view('faculty');
    }
    else
    {
      $this-&gt;load-&gt;view('Login');
      echo "Invalid Username or Password";
    }
  }
  </code></pre>
  
  <p><strong>VIEW</strong></p>
  
  <pre><code>&lt;?php 
  
  if (!$this-&gt;session-&gt;userdata('$data'))
  {
      echo "Please Login";
  }
  else
  {
  
  }
  
  ?&gt;
  
  &lt;!DOCTYPE
  </code></pre>