带有 javascript 计时器的 php - 当用户在计时器为零之前离开页面时会发生什么

发布于 2024-10-01 16:26:42 字数 306 浏览 4 评论 0原文

我有一个游戏,用户可以赢得一些东西。 一旦他获胜,他就有 60 秒的时间填写他的地址、姓名等,否则他会失去他的价格,其他人可以拿走它。 当他在 60 秒内没有填写地址时,他会被重定向到一个抱歉为时已晚的页面,并且他会失去价格。 当他填写地址时,他会被重定向到确认页面并可以索要他的价格。

我用 php 做了这个,计数器是用 javascript 写的。 当时间= 0时,javascript将进行重定向,

我如何控制用户要么转到确认页面,要么转到迟到的页面。 我想知道即使用户离开页面,我如何才能确保 javascript 倒计时确实计数为零。

多谢

i have a game whene the user can win something.
as soon as he wins he has 60 seconds to fill in his adress name etcotherwise he lose his price and someone else can take it.
when he not fills in the adress in 60 seconds then he gets redirected to a sorry too late page and he lose his price.
when he fills in his adress he gets redirected to a confirmation page and can claim his price.

i made this with php and the counter is in javascript.
the javascript will do the redirect when time = 0

how can i controll that the user either goes to the confirmation page or to the soory to late page.
i'm wondering how i can be sure that the javascript countdown is really counted to zero even wehn the users leaves the page.

thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绳情 2024-10-08 16:26:43

您不能确定 - 您的用户可以轻松修改您的 JavaScript 以增加时间限制,甚至完全禁用计时器。

时间限制应在服务器上验证。我建议当时间限制开始时,服务器在数据库中存储一行,存储它是哪个用户以及时间限制何时开始。当用户提交时,服务器应该检查数据库以查看已经过去了多少时间。

我还认为只有 60 秒的时间来填写你的地址是相当苛刻的,但这是你的决定。

You can't be sure - your users can easily modify your javascript to increase the time limit or even disable the timer completely.

The time limit should be validated on the server. I would suggest that when the time limit starts the server stores a row in the database storing which user it is and when the time limit started. When the user submits the server should check the database to see how much time has passed.

I also think that having just 60 seconds to fill in your address is rather harsh, but that's your decision.

半城柳色半声笛 2024-10-08 16:26:43

尝试不要仅信任 javascript 来完成这项工作,当用户获取表单填写其数据时,使用 php 在会话或数据库中写入时间 - 检查此开始时间和结束时间之间的差异(使用 php)-用户向服务器提交表单的时间
当 diff<=1min 时向他显示确认信息,或当 diff>1min 时向他显示抱歉迟到

try not to trust only javascript for this job, use php to write the time in the session or an database when the user gets the form to fill in his data - check the difference (with php) between this starting-time and the end-time when the user submits the form to the server
and show him the confirmation when diff<=1min or show him sorry-to-late when diff>1min

剑心龙吟 2024-10-08 16:26:43

你可以这样做,使用 javascript 作为用户界面,当用户离开文件时,对 php 脚本执行 ajax 调用并保存他刚刚在字段中输入的数据。真正的计数是在php中进行的,所以当用户提交最终数据时,你还应该检查php中的时间是否过期。

我认为这对于您的问题来说是一个很好的解决方案。

you could do this, use javascript for user interfase, and when user leaves a filed execute ajax call to php script and save data that he just entered in field. And real counting make in php, so when user submits final data u should also check if time expired in php.

I think this is good solution for your problem.

燃情 2024-10-08 16:26:43

如果您使用 Javascript 执行此操作,任何人都可以阅读您的脚本并找到奖品页面的位置。

相反,请使用 microtime() 来运行 PHP 计时器。当他们看到“你赢了”页面时,你就可以开始了。它将在后台运行,并且不依赖于任何用户交互。

If you do this in Javascript, anybody can read your script and find where the prize page is.

Instead, run your timer with PHP using microtime(). You can start when they see the "You Win" page. It will run in the background, and won't depend on any user interaction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文