How to access Controller class in CodeIgniter
Take that method out of that controller.
Assuming you have a User model, that is a great place to put it if it is authenticating a user and logging them in.
Other places that you may put repeatable code is in helpers (static functions) and libraries (classes).
Take the function to a Model or code it in a library.
Helpers I won't recommend as you are not advised to access the database from Helpers.
Easy way out is put it in a model say user_model and call it by any controller anywhere.
I put a check login method in base controller, which is extended by all controllers. Now if a controller's action requires users to be logged in, I call it there like parent::_check_login()
, if the whole controller requires it I call it from the constructor of that controller, that's all.