Monday, 13 August 2018

HOW TO ADD TIME AND COMPARE DATETIME OBJECTS IN PHP

// first get the current time when the visitor requests the reset page from the server
$now = new DateTime();

// next get the created_at date of the reset key
$reset_key_date = new DateTime($user->reset->created_at);

// next add two hours to the reset key creation time
$reset_key_date->add(new DateInterval('PT2H'));

// if $now is greater than the reset key date (+2 hours), return error etc
if ($now > $reset_key_date) {
// you're too late! try again!
}

// otherwise continue on and allow the user to reset their password.

0 comments:

Post a Comment