I am assigning a token to user when he logs in, this token will be stored in database and will expire within 12 hours.
For this when the user logs in it will be shown in a view,
**my view is **
<a href=" <?php echo site_url('admin/checkval') ?> ">check valididty of token</a>
when he clicks on this,
My Controller
public function checkval(){
$this->load->library('session');
$goal = $this->session->userdata('user_id');
$uid = $goal[0];
$token = $goal[1];
$this->load->model('loginmodel');
$check_id = $this->loginmodel->token_valid($uid, $token);
if($check_id){
$data['query'] = $this->loginmodel->get_last_ten_entries();
$this->load->view('admin/account', $data);
print_r($data);
echo "valid";
}else {
echo "invalid";
}
}
if his token is valid he will be shown list of users
model
public function token_valid($uid, $token){
$responce = $this->db->query("SELECT expired_at FROM user_auth
WHERE id = '$uid' AND token = '$token'");
$date = strtotime($responce->result());
echo "$date";
$cdate = date("Y-m-d H:i:s");
$cdate = strtotime($cdate);
$interval = date_diff($date,$cdate);
$hour = $interval->h;
if(h<12){
return TRUE;
}else {
return FALSE; // code...
}
}
database
In user_auth table i have,
id int(50),token varchar(500),expired_at datetime
but when i do this, the error occurs as follows,
strtotime() expects parameter 1 to be string, array given
date_diff() expects parameter 1 to be DateTimeInterface, boolean given
Trying to get property of non-object0
Use of undefined constant h - assumed 'h'
I think once the first error is resolved, others will go away. How do i do that? What am i doing wrong here? Thank you for your suggesions