title: How to implement a secured login/logout in Codeigniter?
body: <p>I am making a secured login for the system I am creating with CI since there should be an admin control of the system.</p>
  
  <p>My approach was that I made a file on the application/core directory named MY_System.php where I got this line of code:</p>
  
  <pre><code>class MY_System extends CI_Controller
  {
   function __construct()
   {
      parent::__construct();
  
   }
  }
  </code></pre>
  
  <p>Then I also have Admin_Controller.php where I got this code :</p>
  
  <pre><code>class Admin_Controller extends MY_System
  {
  
  function __construct()
  {
      parent::__construct();
  
      $this-&gt;is_logged_in();  
  }
  
  function is_logged_in()
  {
      $is_logged_in = $this-&gt;session-&gt;userdata('is_logged_in');
  
      if(!isset($is_logged_in) || $is_logged_in != true)
      {
          redirect(base_url(). 'login');
      }
  }
  }
  </code></pre>
  
  <p>The 2 files above are saved inside the core folder of the framework.</p>
  
  <p>While on the controllers directory of the system, I got several controllers let's say Person in instance where I have this code:</p>
  
  <pre><code>class Person extends Admin_Controller
  {
       function __construct()
       {
           parent::__construct();
       }
  }
  </code></pre>
  
  <p>I believe that in this way, whenever the are pages of the system that shall be restricted I would use the Admin_Controller as the parent of the classes so that the users can't directly access the pages.</p>
  
  <p>Now, my problem is that as I would click logout, the session will be destroyed and the user's data are emptied thus, the user must be redirected to the login page but it doesn't go that way because whenever I would click the back button of the browser right after I click logout, the previous page where the user was would still show up but when I click the links on those page, that's the time when the user will be redirected to the login page. What I want is that, after clicking logout and if he/she attempts and clicks the back button of the browser, he/she must be redirected to the login page.</p>
  
  <p>Does anyone know the solution for my problem? Any help is appreciated. Thanks in advance.</p>