Force user to login method in Codeigniter without checking Session in every method.


If you need to secure every method of a Codeigniter controller, you can do it with one line instead of checking the session in every method before doing anything else. In the constructor of the controller simply check that $this->router->fetch_method is not equal to your login method and that a user isn’t logged in. If you meet both of these criteria, redirect to the login method.

, ,

  1. No comments yet.
(will not be published)