Authentication checking - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Authentication checking (/showthread.php?tid=52704) |
Authentication checking - El Forum - 06-22-2012 [eluser]someone [/eluser] Hello, I'm going to write some little authentication for my news system, but I don't know how to check authentication from some other controller. So I will write controller with name Authentication and I would like to check auth in other controller which is named Admin. To this controller can access only those who are logged in (for now, after I will create user groups) and nobody else. I have never used construct in my controller so I don't know what do I have to type in it to restrict access to non-users. Thanks for help! :-) Authentication checking - El Forum - 06-22-2012 [eluser]InsiteFX[/eluser] CodeIgniter Base Classes: Keeping it DRY Authentication checking - El Forum - 06-22-2012 [eluser]LuckyFella73[/eluser] You could extend the CI_Controller with an Admin_Controller. In your Admin_Controller construct you check for logged in user. Then extend all controllers where access has to be restricted with the Admin_Controller. In application/core you would have: Code: // Admin_Controller.php In your restricted controllers you would have: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I guess you need that in your config.php also: Code: // application/config/config.php Hope that makes sense to you Authentication checking - El Forum - 06-23-2012 [eluser]someone [/eluser] I understand this, but it make sense to create new Admin_Controller if I will use this "protection" on just one controller? Authentication checking - El Forum - 06-25-2012 [eluser]LuckyFella73[/eluser] I set up all my projects having a MY_Controller, Admin_Controller and Frontend_Controller. Maybe you need to check for logged in user in an other controller later then you can just extend the new controller with Admin_Controller without much hassle. It's no big deal to set it up that way from beginning so why not just do it? Authentication checking - El Forum - 06-26-2012 [eluser]JamieBarton[/eluser] I'd create a MY_Controller.php file which contains perhaps: Code: public function is_logged_in() { Then you'd have in the auth library the logic behind that, that would check if the session existed for that for user, if not it would return FALSE. |