I am try to figure out how to check current time against time in database and header the user to "expired page" if the current time is greater than the one in database "1 hour"

$email = $token = $check_time = "";

$crossToken = $db->prepare("SELECT email, token, check_time FROM pw_reset_company WHERE token=? LIMIT 1");
$crossToken->bind_param('s', $c);
if ($crossToken->execute()) {
    $crossToken->bind_result($email, $token, $check_time);
    $rowCount = $crossToken->num_rows;
    if ($crossToken->fetch()) {
        $contactEmail = $email;
        $timeToExpire = $check_time;
    if ($rowCount > 0) {
        $checkTime = date("H:i:s", time());
        <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
            <label for="password">Enter New Password</label>
            <input type="password" name="password" id="password">
            <label for="confirm">Enter New Password</label>
            <input type="password" name="confirm" id="confirm">
            <input type="submit" name="subNewPass" id="subNewPass" value="Reset Password">
    } elseif ($_GET['c'] && !(empty($_GET['c']))) {
2 Years
Discussion Span
Last Post by johnef_sh

I had a same problem but i need a minutes, so you get a new time then subtract 1 hour or in my case 10 minutes from it and then you ask is that time greater then that time in database if it is you do what you want to do if not they your result from SQL will be nothing and that is it...

$newTime = date("Y-m-d H:i:s");

$timeLess10m = date("Y-m-d H:i:s", strtotime('-10 minutes', strtotime($newTime)));

$SQL="SELECT * FROM `DB` WHERE `ID` = 1 AND `TIME` < '" . $timeLess10m ."'";

$rez = mysql_query($SQL) or die("Error: ".mysql_error());
$num_rows = mysql_num_rows($rez);
if ($num_rows > 0) {
    // 10 minutes is passed
} else {
    // we are still in 10 minutes period...

I hope this would help, Mike.

Edited by milil


Hi milil I edit my code to this

if ($rowCount > 0) {
        $newTime = date("Y-m-d H:i:s");
        $checkTime = date("Y-m-d H:i:s", strtotime('+1 hour', strtotime($newTime)));
        if ($dbTime < $checkTime) {

and I think it's the same what you have provided but still no luck
any other ideas


check_time is a datetime, time, or a varchar (with timestamp) field in the database? I am asking this because in your question you seem to check from a time field but in your response you check for a date-time field. Also, in your response your $checkTime will always be 1 hour after current time. And in your if condition that header() will always be written.

If the field in the database is of datetime type, why not try this:

$currentTime = time();
$expireTime = strtotime($dbTime)+3600; // if $dbTime is datetime field in database
if ($expireTime < $currentTime) {

Dear Adrian_5 thanks really you solved my problem it's working now fine

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.