Login Box and Logged In User data on each page. - 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: Login Box and Logged In User data on each page. (/showthread.php?tid=39757) |
Login Box and Logged In User data on each page. - El Forum - 03-19-2011 [eluser]thewindsurfer[/eluser] Hello, I'm just starting out with codeigniter and I was wondering what the proper way to put a login box on each page would be. I have already created a regular login page that redirects to a members area. So I understand how that part works. Now instead of a login page i want a small login box on each of my pages. And when the user logs in I want that box to show there username and have a logout button. What is the proper way to implement this. I know I can do it in the view and just check if the login session is set. Then either display the login box or the user info box. But I feel like that wouldn't good practice. Login Box and Logged In User data on each page. - El Forum - 03-19-2011 [eluser]CroNiX[/eluser] There are many ways, but the easiest probably is a base controller or a library that gets autoloaded which would check the login state on each pageload automatically. I generally have what I call mini views, of which one would be a login form, which is part of my template and gets autogenerated on every page page reflecting the current login status/options. Login Box and Logged In User data on each page. - El Forum - 03-19-2011 [eluser]thewindsurfer[/eluser] Thanks for the quick reply. I actually already did a controller part where I have a function call in the construct that checks if the proper session is set. I am curious about this miniview that you spoke of. Is that basically just an include on the theme (like header)?. And what code does that have? Would I make my controller function return TRUE or FALSE if a user is logged in? And then call that function from my "miniview" and create a the proper form accordingly with an if else? Login Box and Logged In User data on each page. - El Forum - 03-20-2011 [eluser]thewindsurfer[/eluser] So I have a solution to this. But I want to check with the experts here to see if my logic is sound and if there is a better more efficient way to do this. I created a MY_Controller and put it into my application/core Here is its code Code: class MY_Controller extends CI_Controller { Basically the function checks for the "is_logged_in" session and then creates a variable in the $data array called "is_logged_in" and sets it to either true or false. It then sets that variable to global. So the views can use it without me having to set it in individual controllers. I also put a return on this so that I can call this function inside individual controllers to see if a user is logged in. (is there a better way to do this part?) I then created a mini-view called loginbox.php which I call where I need my loginbox to be display (currently my header). Here is the code. Code: <?php From what I can tell this works. Is there a better more efficient way to do this? and security wise should it be ok? Thanks. Login Box and Logged In User data on each page. - El Forum - 03-26-2011 [eluser]Varadha[/eluser] Hi, I am a beginner in code igniter. I have my controllers basic setup as follows: application/core/MY_Controller.php ----------------------------------- Code: class MY_Controller extends CI_Controller { application/controllers/Admin_Controller.php --------------------------------------------- Code: class Admin_Controller extends MY_Controller { application/controllers/admin.php --------------------------------- Code: class Admin extends Admin_Controller { It works fine with login credentials. If i access the members_area() without login, it just loads the welcome view. I have to include many number of functions after login. Should i verify the login session for each and every function? Is there any other way to solve this? I need help on this. Please guide me :question: . Regards Varadha |