CodeIgniter Forums
function is_logged - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: function is_logged (/thread-53516.html)



function is_logged - El Forum - 07-27-2012

[eluser]Felipe Deitos[/eluser]
Hi!

I got a newbie question...
I have a function that check if user is logged...

I must put this function in every controller?
What it the best practice to do something like this without repeating the same function in every controller.

Thanks for the attention!


function is_logged - El Forum - 07-27-2012

[eluser]Unknown[/eluser]
I usually use it like this in every controller that needs authentication.
Code:
<?php
public function admin()
{
     is_logged()
     {
             // admin contents

     }else{
         redirect('login_page');
     }
}
?>



function is_logged - El Forum - 07-27-2012

[eluser]Felipe Deitos[/eluser]
Well i am doing like this, putting the is_logged and is_admin in every page..
I just want to know if this is the better way, and if there is other ways to do that

Thanks for the answer!
Cheers!