CodeIgniter Forums
Prevent direct access - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Prevent direct access (/thread-29554.html)



Prevent direct access - El Forum - 04-13-2010

[eluser]Giga[/eluser]
I created an authentication mechanism that makes access to different areas for each type of user logged. However, to avoid direct access I thought of using a hook before the controller ... This is a good idea?
I would like to avoid writing the control code for each function of the controller ...
Or just put the control code in the constructor of the controller?


Prevent direct access - El Forum - 04-13-2010

[eluser]Narkboy[/eluser]
Always keep it simple! If your auth code controls access to the functions within the controller, then run it in the constructor and you're done.

If the auth code controls access to other controllers or to other assets, then I would probably place it into the constructor of a library, and auto-load the lib. I try to avoid hooks and have never needed to have one yet.

More detail on what the auth code does would help to understand exactly what you're after!

GL!