title: CodeIgniter check sessions in every controller?
body: <p>I have define this controller to check user session:</p>
  
  <pre><code>class SessionController extends CI_Controller {
  
  function __construct()
  {
      parent::__construct();
      $this-&gt;is_logged_in();      
  }
  
  function dashboard_area(){
      $data['main_content'] = 'dashboardView';
      $this-&gt;load-&gt;view('dashboardTemplate/template', $data);         
  }
  
  function is_logged_in()
  {
      $is_logged_in = $this-&gt;session-&gt;userdata('is_logged_in');
      if(!isset($is_logged_in) || $is_logged_in != true)
      {
          echo 'You don\'t have permission to access this page.';
          die();
          //$this-&gt;load-&gt;view('login_form');
      }
  }       
      } ?&gt;
  </code></pre>
  
  <p>and in my login controller I do this..</p>
  
  <pre><code>   class LoginController extends CI_Controller {
  
   function index(){      
      $new['main_content'] = 'loginView';
      $this-&gt;load-&gt;view('loginTemplate/template', $new);          
  }   
  
  function verifyUser(){      
      //getting parameters from view 
      $data = array(
              'username' =&gt; $this-&gt;input-&gt;post('username'),
              'password' =&gt; $this-&gt;input-&gt;post('password')
      );
  
  
      $this-&gt;load-&gt;model('loginModel'); 
      $query = $this-&gt;loginModel-&gt;validate($data);
  
            if ($query){             //if the user c validated
          //data variable is created becx we want to put username in session
              $data = array(
                  'username' =&gt; $this-&gt;input-&gt;post('username'),
                   'is_logged_in' =&gt; true 
              );
  
           $this-&gt;session-&gt;set_userdata($data);
           redirect('sessionController/dashboard_area');
      }
      else
       {
          $this-&gt;index();
      }
  }
  function logout()
  {
      $this-&gt;session-&gt;sess_destroy();
      $this-&gt;index();
  }
  }   
  ?&gt;
  </code></pre>
  
  <p>now the problem is I have many controllers how to I use this .. I don't want to make new session controllers again and again ... and if there is any more good for handling sessions in more then one controller then please let me know .. 
  iIhave seen this answer also ... but after applying the answer no 14 .. it gives me this error</p>
  
  <pre><code>Fatal error: Class 'MY_Controller' not found in C:\xampp\htdocs\StockManagmentSystem\application\controllers\categoryController.php on line 4
  </code></pre>
  
  <p>I am working in a latest code igniter</p>