I have a Laravel application where I regularly check the loggedin user with a beating for every 3 seconds (demo target, actually 5 minutes). For each bit, I check to see if the last user activity with the current time is also 5 minutes. If so, log out.
Here is my code:
$result = DB::table('db_user')->where('id_user','=',Session::get('id_user'))->where('last_activity','>=',"now() - interval 5 minute")->get(); if(!empty($result)) return Redirect::to('/logout'); else return Response::json('still-alive');
My problem is that this does not work. If I changed the operand to <= , it will exit the system immediately before 5 minutes, if the operand is >= , even after 5 minutes it will not exit the system, can anyone explain why?
-Edit -
Thanks for all the answers, I solved my problems by changing the code:
$result = DB::table('db_user')->where('id_user','=',Session::get('id_user'))->first(); if(!empty($result)) if(strtotime($result->last_activity) < strtotime("-5 minutes")) return Redirect::to('/logout'); else return Response::json('still-alive'); else return Response::json('no-record');
source share