1

我目前在这里需要帮助的同志。我正在基于php进行应用程序开发,该应用程序是quesionaire系统,当用户已经开始(点击开始按钮)时,系统有60分钟的倒计时。到目前为止,当用户处于会话登录状态时,我可以将计时器推送到数据库,我每秒更新数据库。当前系统是当用户注销时倒数计时器将停止,例如倒计时 30 分钟时用户注销。因此,当用户重新登录时,仍然需要 30 分钟。

但我的客户不喜欢它。我的客户想要如果用户已经单击开始按钮,那么倒计时将持续到 60 分钟,即使用户直到 60 分钟才注销或用户关闭浏览器直到 60 分钟。

所以我的问题是如何实现它?用户单击按钮启动时我必须做什么?我想当用户单击按钮开始时会将倒计时计时器推送到数据库 mysql,尽管用户关闭浏览器倒计时总是推送到数据库。

结构数据库表为:

- id (int) auto_increment;
- user_id (int);
- residual_time (int); <--I push it per second, so per second will update it until 0.

我的服务器使用 linux ubuntu 服务器。我是服务器的所有者。

谢谢你。

4

1 回答 1

0

我会完全按照@Joachim 的建议去做,并遵循这个流程:

  • 替换residual_timestart_time日期时间类型。
  • 添加last_update类型为日期时间。
  • 当用户点击开始设置和start_timeMySQL功能last_updateNOW()
  • 编写一个函数,每 30 次用 AJAX 运行一次?其次检查是否last_update已过去 60 分钟start_time,如果是,则停止问卷并清除start_timelast_update

现在让我们假设用户在分配的中间时间退出并注销,然后重新登录以继续:

//sudo code example
//check if start_time is set
if(isset(start_time)){
    //check if last_update time is set
    if(isset(last_update)){
        //calculate the time difference in minutes from previous start_time and last_update time
        time_diff = last_update - start_time;
        //if time difference is less than alloted time example 60 minutes
        if(time_diff < 60 minutes){
            //update start_time with current time less time difference for already used time
            start_time = NOW() - time_diff minutes
        //if time difference is greater than the allotted time
        } else {
            //kill the page with the time expired message
            die(Your time has expired);
        }
    //if last_update time is not set
    } else {
        //set start_time to NOW()
        start_time = NOW();
    }
//if start_time is not set
} else {
    //set start_time to NOW()
    start_time = NOW();
}
于 2013-06-07T19:51:03.823 回答