php - How to check user if logged in My_Controller at CodeIgniter -


i new codeigniter. want create new controller checks other controller , methods if user logged in already. using session way. stated here codeigniter - how check session used @ every methods , here .

i need create my_controller.php inside application/core folder.

<?php class my_controller extends ci_controller {     function __construct()     {         parent::__construct();     } } ?> 

public_controller.php

<?php class public_controller extends my_controller {     function __construct()     {         parent::__construct();         // session stuff here :)     } } 

admin_controller.php

<?php class admin_controller extends my_controller {     function __construct()     {         parent::__construct();         // session stuff here :)     } } 

what should add inside 2 new controller can use in controller base.php? or how can implement session checking? sorry, hard me explain.

make ur my_controller this:

<?php class my_controller extends ci_controller {     function __construct()     {         parent::__construct();         $this->load->library('session'); // if loading session library automatically in autoload model, dont need line.         /*---- can session related work in my_controller if needed-----*/         if($this->session->userdata('logged_user')== true)            {                // session related work;            }     } } ?> 

then in public controller make following changes

<?php include('my_controller.php'); class public_controller extends my_controller {     function __construct()     {         parent::__construct();         /*---- if session checking done in my_controller might not need here again---*/         if($this->session->userdata('logged_user')== true)            {                // session related work;            }     } } 

similarly proceed other controller


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -