title: CodeIgniter: checking if user logged in for multiple pages
body: <p>I have a controller, which maps to section of my site and all of the pages within it (methods) should only appear if the user is logged in. Otherwise they should be redirected back to a login screen.</p>
  
  <p>To get it working I've just done this:</p>
  
  <pre><code>function index() {
  
      if ($this-&gt;session-&gt;userdata('logged_in')) {
          $this-&gt;load-&gt;view('main');
  
      } else {
          redirect('/login');
      }
  }
  
  function archive() {
  
      if ($this-&gt;session-&gt;userdata('logged_in')) {
  </code></pre>
  
  <p>and so on... repeating that check in each method. What's the simplest way of doing this check once for multiple-or-all methods in the controller? </p>