in the project I'm creating I need to check if the user is logged in or not, the tutorials I have seen do explain how to authenticate in the controllers and give access to a page or not. But I want all the pages to be visible to everyone but only show certain options if a user is logged in or not.
something like this in the views
if(is_logged_in()):
//some options here
else:
echo "you need to login to have more options";
endif;
so where should I add this code? in the helper folder?
EDIT: I'm now checking in the views like this, it works but I don't know if it's a best practice. The 'is_logged_in' is something I set to true when the credentials were validated
if($this->session->userdata('is_logged_in'))
EDIT:
so if I make a helper to call that function. Can I check using the userdata function?
this is the function that creates the session
$data = array(
'username' => $this->input->post('username'),
//usertype toevoegen hier
//email toevoegen
//deposit money
'is_logged_in' => true
);
$this->session->set_userdata($data);
How could I used the session data in the function in my helper file?