i have crated a custom library file for the login validation. if i call the custom library at before $this->load->library('form_validation');
class VerifyLogin extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('loginuser');
$this->load->library('validate_login','','session_validation');// where validate_login is the custom library class inside applications/libraries/validate_login.php
}
function index()
{
//my code
$this->load->library('form_validation');
}
}
This is the error i got $this->load->library('form_validation'); it works perfectley. i just want to know Why this code works? Am i overwriting the default libraries?
Message: Undefined property: VerifyLogin::$form_validation
if i load the library after
class VerifyLogin extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('loginuser');
$this->load->library('form_validation');
$this->load->library('validate_login','','session_validation');// where validate_login is the custom library class inside applications/libraries/validate_login.php
}
function index()
{
//my code
}
}
This is my validate_login library.
class Validate_login extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('loginuser');
$this->load->helper('url');
}
function is_logged()
{
if(isset($this->session->userdata['my_session_id']))
{
if(strlen($this->session->userdata['my_session_id']))
{
return TRUE;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}
function validate_login()
{
$session_id=$this->session->userdata['my_session_id'];
$this->db->select('last_activity,user_data');
$this -> db -> from('sessions');
$this->db->where('session_id',$session_id);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
$results=$query->result();
$active_session=$this->session_alive($results[0]->last_activity,$session_id);
if($active_session==TRUE)
{
return TRUE;
}
else
{
$this->verifylogin->logout();
}
}
else
{
return false;
}
}
function session_alive($valid_till,$session_id)
{
$time_limit=$this->config->item('sess_expiration');
if (time() - $valid_till > $time_limit)
{
return FALSE;
}
else
{
if($this->update_session($session_id)==TRUE)
{
return TRUE;
}
else
{
return FALSE;
}
}
}
function update_session($session_id)
{
$new_time=time();
$data=array('last_activity'=>$new_time);
$this->db->where('session_id',$session_id);
$this->db->update('sessions',$data);
if($this->db->affected_rows())
{
return TRUE;
}
}
}