如果一小时过去,请检查数据库中当前时间与标题到期页面的当前时间

时间:2014-09-16 11:25:40

标签: php mysqli

这是一个"重置密码表单"我需要让这个页面过期一小时,所以如果用户点击链接再次到达页面一小时后他将直接到期页面,所以我在我的数据库中创建了这个表格,这个列的内容是" check_time&# 34; db列类型是" datetime"现在 我需要根据数据库中的时间检查当前时间,并在一小时过去时将用户标题为过期页面

$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);
    $crossToken->store_result();
    $rowCount = $crossToken->num_rows;
    if ($crossToken->fetch()) {
        $contactEmail = $email;
        $timeToExpire = $check_time;
    }
    if ($rowCount > 0) {
        date_default_timezone_set("UTC");
        $checkTime = date("H:i:s", time());
        if($timeToExpire>$checkTime){
            header("Location:?pid=expired");
        }
        ?>
        <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">
        </form>
    <?php
    } elseif ($_GET['c'] && !(empty($_GET['c']))) {
        header("Location:?pid=expired");
    }
}

修改 对不起,如果我没有正确描述我的问题

这是有问题的代码部分

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) {
            header("Location:?pid=companyManagePasswords&mp=expire");
        } 

我昨天编辑这部分就是这样,每当我尝试访问重置密码页面时,它会重定向到过期页面,它应该在一小时后完成。

请帮我编辑此部分,使重置页面在1小时后过期。

有人建议做这样的事情

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

仍然不是我想要的。 任何想法

0 个答案:

没有答案