title: Best place to check if logged-in -- Codeigniter/PHP
body: <p>Currently I use the following for checking is a user is logged in:</p>
  
  <pre><code>function only_a_loggedin_user_can_do_this()
  {
      if($user_is_logged_in)
      {
         do something that only users can do
      }
      else
      {
          redirect('/login_page/');
      }
  }
  </code></pre>
  
  <p>but if my controller has many functions is a bit of a pain in the arse to write or make changes. </p>
  
  <p>Whats the best way to achieve what I want but in a more simplistic way that is easier to update. I was thinking of the below,</p>
  
  <pre><code>function check_if_logged_in()
  {
      if($user_is_logged_in)
      {
         function only_a_logged-in_user_can_do_this()
         {
         }
  
         function or_this()
         {
         }
  
      }
      else
      {
          redirect('/login_page/');
      }
  }
  </code></pre>
  
  <p>but would that mean adding adding something to the URI string, eg </p>
  
  <p>www.example.com/index.php/check_if_logged_in/only_a_logged-in_user_can_do_this/</p>
  
  <p>Whats the best way to implement this?</p>