Say my controller named Book , I have many methods like get_book(); read_book(); remove_book();
No methods in the class can be used without user login, and I can get user_id from the session.
My question is: what are / are the best ways to check if a user_id session is user_id so that I can use the methods?
I am currently thinking of creating an is_logged_in() method and applying it to all methods with an if-else statement, for example
if($this->is_logged_in() { //do something } else { //redirect to home }
Is it really long and tiring? Is there a better way to achieve this?
I read the link
codeigniter check user session in each controller
But it seems to me that I should still apply the is_logged_in check with each method.
Thanks for helping me!
user826224
source share