[eluser]JohnDoerther[/eluser]
Hi guys,
I am currently implementing user profiles on a website, and the login system works great using Erkana.
Now, I use the constructor to check in every controller if the user is logged in or not, and depending on that, I redirect to a login page (depends on the page - some pages are protected, others are not...)
Now, in a header file that is included in every page (secured and not secured) I am looking for an easy way to check if a user is either loged in, or not.
This is what I have so far:
For the constructors with secured pages:
Code:
function User(){
parent::Controller();
$this->load->library('Erkanaauth');
$this->load->helper('url');
if (!$this->erkanaauth->try_session_login()) {
redirect('front/account/login');
}
}
The non-secured pages do not have this code in the constructor.
Now, what I want to do, is know from my views if a user is logged in or not. I know I can do this by using
But that only seems to work for views called by protected controllers, so only pages where the user is actually logged in.
So in other words, I want an easy way to include user state in my views, both for secured pages and for unsecured pages.
I know I could do something like the following for every single function:
Code:
if (!$this->erkanaauth->try_session_login()) {
redirect('front/account/login');
$data['loggedIn'] = true;
}
and use variable
in my views, but there has to be an easier way that applies to the complete class instead of to each independent function.
Thanks in advance, I am really stuck on this...