Xtremer360 Posted September 5, 2011 Share Posted September 5, 2011 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 More sharing options...
voip03 Posted September 5, 2011 Share Posted September 5, 2011 $lock_date format? Link to comment https://forums.phpfreaks.com/topic/246499-time-difference/#findComment-1265751 Share on other sites More sharing options...
Xtremer360 Posted September 5, 2011 Author Share Posted September 5, 2011 The lock_date in the db is 2011-09-05 15:11:08. Link to comment https://forums.phpfreaks.com/topic/246499-time-difference/#findComment-1265752 Share on other sites More sharing options...
voip03 Posted September 5, 2011 Share Posted September 5, 2011 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 More sharing options...
Xtremer360 Posted September 5, 2011 Author Share Posted September 5, 2011 i'll try and come up with something Link to comment https://forums.phpfreaks.com/topic/246499-time-difference/#findComment-1265768 Share on other sites More sharing options...
monkeytooth Posted September 5, 2011 Share Posted September 5, 2011 // 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.