Get Hook Session Data in CodeIgniter

I am using codeigniter. I want to use hooks to authenticate login. This means that I want each controller to verify session data and login time. For tht, I inserted the loggin time in the .if loggedin session or not, and the time since it logged in, so I want to use hooks. I want to access session-> userdata parameters from an array, but I cannot figure out how to get these values ​​from tht array. I want to get the registration time from the array and update when the user clicks or moves around the site. This is my code:

//enter code here
$hook['post_controller_constructor'][] = array(
                           'class'    => 'Authenticate',
                           'function' => 'loginCheck',
                           'filename' => 'authenticate.php',
                           'filepath' => 'hooks',
                           'params'   => array()
                           );

class Authenticate
{

    private $CI;

    function __construct()
    {
        $this->CI =& get_instance();

        if(!isset($this->CI->session)){  //Check if session lib is loaded or not
              $this->CI->load->library('session');  //If not loaded, then load it here
        }
    }

   function loginCheck()
   {

        if(!$this->CI->session->userdata){
            if($this->CI->session->userdata('uid')=="XYZ")
            {
                echo "Valid User"; //it wont get inside this if
            }
        }
    }
}

I have data in:

$this->CI->session->userdata array :
Array ( [session_id] =>afaf... [ip_address] => ::1 [user_agent] => Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 [last_activity] => 1408553094 [user_data] => [logged_in] => Array ( [Id] => 1 [user_name] => buzz [login_time] => 22:14:54 [uid] => XYZ ) )

How can I extract ID,user_namein the hook?

+4
1
function loginCheck()
{
    $session_userdata = $this->CI->session->userdata('logged_in');
    if($session_userdata['uid']=="XYZ")
    {
        echo "Valid User"; //it wont get inside this if
    }
}
+4

All Articles