title: How can I use session in a library in CodeIgniter?
body: <p>I want to check if user is logged in CodeIgniter by using my library in the controller's constructor.</p>
  
  <p>This is my library:</p>
  
  <pre><code>class Administrator_libs {
  
      public function validate_authen(){
          if( $this-&gt;session-&gt;userdata('user_authen') ){
              redirect(base_url().'admin/login/');
          }   
      }
  }
  </code></pre>
  
  <p>And this is my controller:</p>
  
  <pre><code>class Administrator extends CI_Controller {
  
      public function __construct(){
          parent::__construct();
          $this-&gt;load-&gt;library('administrator_libs');
          $this-&gt;administrator_libs-&gt;validate_authen();
          $this-&gt;load-&gt;model('mod_menu');
      }
  }
  </code></pre>
  
  <p>But I get this error message:</p>
  
  <pre><code>Undefined property: Administrator_libs::$session
  </code></pre>
  
  <p>How can I use session in a library in CodeIgniter?    </p>