我正在使用codeigniter我想使用Hook进行登录验证.这意味着我希望在每个控制器中检查会话数据和登录的时间.因为我在会话中插入了登录时间.如果登录或不登录,那么自从他登录以来的时间.所以我想使用挂钩.我想从数组访问session-> userdata值,但我不知道如何从数组中获取这些值.我想从数组获取记录时间并更新whenevr用户点击或在站点上导航.这是我的代码:
//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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有数据:
$this->CI->session->userdata array :
Array ( [session_id] …Run Code Online (Sandbox Code Playgroud)