gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:02:34 26 4
gpt4 key购买 nike

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

计时器将使用 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 会是您的答案。

关于javascript - 如何使用秒表javascript中的php在mysql数据库中存储计时器值而不使用隐藏输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56059429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com