I am having trouble checking time. I loop through users in my database using this function to check each one and if time has passed 1 minute. As I loop through the top user (me) has the same time as current time (1 minute has not passed). Other users are fake and their time is from earlier today (1 minute has def passed). However my function returns false every time.
public function checkOnline($username)
{
$user = $this->load->model('user')->getUser('username', $username);
$last_active = strtotime($user['last_active']);
var_dump(date('Y-m-d g:i:s', time()) . ' ' . $user['last_active']);
var_dump(time() . ' ' . $last_active);
if (time() - $last_active > 1 * 60) {
echo 'false';
return false;
} else {
echo 'true';
return true;
}
}
The var dumps return this for the first user (me) return this.
'2018-02-04 4:49:54 2018-02-04 4:49:54'
1517798994 1517755794
The var for other users return this.
'2018-02-04 4:49:54 2018-02-04 3:09:03'
'1517798994 1517749743'
Why is my function always returning false?
EDIT:
Here is the loop where I check
foreach ($users as $user) {
if ($this->checkOnline($user['username']) === true) {
$is_online = '<span class="text-green">Online</span>';
} else {
$is_online = '<span class="text-red">Offline</span>';
}
}
Output:
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 5:53:57' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517759637' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false
C:\path\UsersController.php:124:string '2018-02-04 5:53:57 2018-02-04 3:09:03' (length=37)
C:\path\UsersController.php:125:string '1517802837 1517749743' (length=21)
false