Hi all I am really asking a more of a theoretical question here - but I am creating an application which is kind of like a true false answers webpage using PHP and have found that I now require the use of a timer. I am using MVC (codeigniter) and reload the controller when the user goes to the next question. I was wondering if you guys have any ideas of the best way to implement a timer - I can't put this on the page in JS as I assume that the timer will restart and haven't found a way of doing this in php. Is there a best practice I am missing like another controller to just perform the timer? - I apologise if this is a truly stupid question as I said its not really a coding issue yet more of a theoretical - I am also a complete beginner so please have patience
1条回答 默认 最新
- donglun7151 2014-02-08 12:34关注
You can save the starting time in PHP and put it in a $_SESSION variable. after that give it to javascript to countdown/countup each page. even if the user manipulate your js timer, you'll know how much time has really passed in php
sample code: in your first page, where you start your quiz:
<?php session_start(); $_SESSION['startTime'] = time(); ?>
and now in other pages:
<?php session_start(); $timePassed = time() - $_SESSION['startTime']; // pass it back to javascript ?>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥30 关于用python写支付宝扫码付异步通知收不到的问题
- ¥50 vue组件中无法正确接收并处理axios请求
- ¥15 隐藏系统界面pdf的打印、下载按钮
- ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
- ¥15 基于pso参数优化的LightGBM分类模型
- ¥15 安装Paddleocr时报错无法解决
- ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
- ¥50 分布式追踪trace异常问题
- ¥15 人在外地出差,速帮一点点
- ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改