繁体   English   中英

如何使用来自秒表javascript的php在mysql数据库中存储计时器值,而不使用隐藏输入

[英]how to store timer value in mysql db using php from stopwatch javascript without using hidden input

我正在开发一个PHP简单的游戏程序,用户必须解决这个难题。 计时器将运行。 一旦用户解决了谜题,他就会点击提交按钮。 我需要将用户所花费的时间存储在mysql db中。

计时器将使用jquery运行,该值将存储在隐藏字段中。 用户提交后,将从隐藏字段中获取值。

问题是现在每个人都知道如何检查html代码,他们正在手动更改值。

我如何限制它。 计时器将以小时分钟秒和毫秒运行。

我需要使用php存储真正的完成时间,甚至毫秒。 我怎样才能实现这一目标?

我们将根据解决难题的时间较少来宣布获胜者。 请指教我怎么办?

<script type="text/javascript">
var timeBegan = null
    , timeStopped = null
    , stoppedDuration = 0
    , started = null;

function start() {
    if (timeBegan === null) {
        timeBegan = new Date();
    }

    if (timeStopped !== null) {
        stoppedDuration += (new Date() - timeStopped);
    }
    started = setInterval(clockRunning, 10);    
}

function stop() {
    timeStopped = new Date();
    clearInterval(started);
}

function reset() {
    clearInterval(started);
    stoppedDuration = 0;
    timeBegan = null;
    timeStopped = null;
    document.getElementById("display-area").innerHTML = "00:00:00.000";
}

function clockRunning(){
    var currentTime = new Date()
        , timeElapsed = new Date(currentTime - timeBegan - stoppedDuration)
        , hour = timeElapsed.getUTCHours()
        , min = timeElapsed.getUTCMinutes()
        , sec = timeElapsed.getUTCSeconds()
        , ms = timeElapsed.getUTCMilliseconds();


    document.getElementById("display-area").value = 
        (hour > 9 ? hour : "0" + hour) + ":" + 
        (min > 9 ? min : "0" + min) + ":" + 
        (sec > 9 ? sec : "0" + sec) + "." + 
        (ms > 99 ? ms : ms > 9 ? "0" + ms : "00" + ms);
};

$( document ).ready(function() {
    start();
});

</script>

<input type="hidden" id="display-area" value="">

<button id="toggle-button" onClick="stop()">SUBMIT<br>RESULT</button>

任何人都可以通过检查元素来改变隐藏值,我们无法成功运行此谜题。 请建议如何避免用户更改计时器值,让我知道如何使用PHP保存mysql数据库中的计时器值。

我认为Ajax将是你的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM