title: Restricting access in Codeigniter
body: <p>To restrict access to pages one can check like below,</p>
  
  <pre><code>//This code is written on every page accessed by admin. Like, products.php, categories.php
  if( !isset($_SESSION['admin_id'])) {
       header('Location: admin/login.php');
       exit();
  }
  </code></pre>
  
  <p>What is the equivalent of the above code in Codeigniter, if i want to restrict access to every methods of the controller?</p>
  
  <p>can i check for session in constructor like below?</p>
  
  <pre><code>//products.php
  
   class Products extends CI_Controller {
        public function __construct();
  
        if( !isset($_SESSION['admin_id'])) {
             redirect('admin/login.php');               
        }
  }
  
  
  
  //categories.php
  
   class Categories extends CI_Controller {
        public function __construct();
  
        if( !isset($_SESSION['admin_id'])) {
             redirect('admin/login.php');               
        }
  }
  </code></pre>