Jump to content

Time difference


Xtremer360

Recommended Posts

For some reason when I echo $diff and $time_remaining it ALWAYS echos with values of 3 and 7 and not sure why.

 

$lock_date = $row['lock_date'];
                    $current_time = time();
                    
                    // Find out if user is locked out of their account
                    if (($lock_date != "0000-00-00 00:00:00") && strtotime($lock_date) < $current_time) { 
                        
                        $lock_date = strtotime($lock_date);
                        $diff = $current_time - $lock_date;                        
                        $diff = floor($diff/6000);

                        // Take minutes and perform tasks
                        if ($diff <= 10) {
                            
                            // Calculate time remaining
                            $time_remaining = 10 - $diff;

                            // Account locked error
                            $errors = true;
                            $message = "Account is locked! Must wait " .$time_remaining." minutes to log in again!";
                            
                            $output = array('errorsExist' => $errors, 'message' => $message);
                            
                        } else {
                            
                            // Clear the lock
                            $query = "UPDATE users_logins_attempts SET lockDate = NULL, ip_address = NULL, failed_logins = 0 WHERE users_id = '".$users_id."'";
                            $result = mysqli_query($dbc,$query);
                            
                            // Account locked error
                            $errors = true;
                            $message = "Account is unlocked. You may now try to log in again!";
                            
                            $output = array('errorsExist' => $errors, 'message' => $message);
                            
                        } 
                        
                    }

Link to comment
https://forums.phpfreaks.com/topic/246499-time-difference/
Share on other sites

function getMyTimeDiff($t1,$t2)
{
$a1 = explode(":",$t1);
$a2 = explode(":",$t2);
$time1 = (($a1[0]*60*60)+($a1[1]*60)+($a1[2]));
$time2 = (($a2[0]*60*60)+($a2[1]*60)+($a2[2]));
$diff = abs($time1-$time2);
$hours = floor($diff/(60*60));
$mins = floor(($diff-($hours*60*60))/(60));
$secs = floor(($diff-(($hours*60*60)+($mins*60))));
$result = $hours.":".$mins.":".$secs;
return $result;
}
$mytime1 = "10:05:08";
$mytime2 = "21:22:54";
echo $cool = getMyTimeDiff($mytime1,$mytime2);

you should get the general idea from it

Link to comment
https://forums.phpfreaks.com/topic/246499-time-difference/#findComment-1265761
Share on other sites

                    // Find out if user is locked out of their account
                    if (($row['lock_date'] != "0000-00-00 00:00:00") && strtotime($lock_date) <= time()) 
                       { 
                            $output = array('errorsExist' => $errors, 'message' => $message);
                            
                        }
					else
					{
                            
                            // Clear the lock
                            $query = "UPDATE users_logins_attempts SET lockDate = NULL, ip_address = NULL, failed_logins = 0 WHERE users_id = '".$users_id."'";
                            $result = mysqli_query($dbc,$query);
                            
                            // Account locked error
                            $errors = true;
                            $message = "Account is unlocked. You may now try to log in again!";
                            
                            $output = array('errorsExist' => $errors, 'message' => $message);
                            
                        } 

 

when you initially set a lock_date, set that time 10 minutes a head of the time you are setting it at.. so if its 12:00 when your setting it, store it in the DB as 12:10

Link to comment
https://forums.phpfreaks.com/topic/246499-time-difference/#findComment-1265769
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.