duanjing7298 2013-08-23 00:47
浏览 26

too long

I am working on a password reset and I am at the part of where I am checking if the token is within the time range.

This is my code :

            $tokentime = substr($dbtoken[0], 0, 4); // get the DB time that I store with date('hi') . $token
            $now = date('hi'); // Create the now time in same format as $tokentime

            var_dump($now); // This generates : 0838 (couple mines ago) 
            var_dump($tokentime); this generates : 0652 (102 minutes ago)
            var_dump(strtotime($now)); // convert 8380 to unix time
            var_dump(strtotime($tokentime)); // convert 0652 into unix time

            if (strtotime($now) - strtotime($tokentime) >= 600) { // If the unix seconds are equal to or greater then 600 seconds 
                echo "Token Expired";
            } else {
                echo "Not Expiered";
            }

Is my way of thinking correct?

This is the var_dump values :

string(4) "0838" string(4) "0652" int(1377175080) int(1377168720) Token Expired

I have it set to expire in 10 minutes of 600 seconds.

This is my first time working checking differences in time, and storing date values inside of a token like so. I just wanted to know if this is correct way of finding differences in time.

  • 写回答

1条回答 默认 最新

  • duanfei9278 2013-09-27 12:47
    关注

    That's simple: At some moment in time value of time() in your token. Later:

    if (time()-tokentime) > 600)
    {
        // expired
    }
    

    time() will get you so called UNIX timestamp which is timezone independent.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c