我有一个奇怪的目标要实现。
我想要的是,当用户访问某个 HTML 页面时,所有用户在固定时间(比如 20 分钟)内暂时无法访问整组页面。之后,页面应该可以再次访问。也可以临时重定向或审查页面。
为什么?我想对用户在基于 GPS 的游戏中进入禁区进行处罚,该游戏会根据用户的 GPS 数据显示某些网页。最后一部分工作正常。
搜索后我认为它可能适用于 PHP,但我对此经验很少。我知道 HTML 和 CSS,知道如何阅读和修改现有的 JavaScript 和 PHP 脚本,但不知道如何从头开始构建这些代码。
另一个选项(我真的想不通)是让网站在有人进入页面时发送电子邮件,并提供另一个服务,如 "If This Then That"使站点脱机/更改文件名。
最佳答案
像其他回答者建议的那样,创建一个功能,您可以使用它来检查用户是否可以访问该页面的条件。这是一些混合使用 php、python 和 javascript 语法的伪代码哈哈:)
function isAllowedViewing(is_good) {
if (is_good):
if "/var/www/mysite/disable_visits" file exists:
contents = (read contents)
# If 20 minutes has elapsed since first being disabled
if (now.toEpoch() - contents.toEpoch()) > 1200:
remove file from file system
else:
header("Location: thats_bad.php")
else:
if "/var/www/mysite/disable_visits" file does not exist:
create the file on the file system and write now.toEpoch() to it
# Optional:
else:
re-write the current time to the file to reset the 20 minute counter (for every time the user re-visits the bad page)
}
因此,要使用它,您需要在每个页面的顶部调用该函数。如果该页面是您允许正常访问的普通页面,请将 true
传递给该函数。如果要惩罚访问该页面的用户,请传递 false
。
关于php - 在用户访问时暂时使整个站点不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13052866/