1

我有一件奇怪的事情正在努力实现。

我想要的是当用户访问某个 HTML 页面时,在固定时间(如 20 分钟)内,所有用户都暂时无法使用一整套页面。之后,页面应该可以再次访问。也可能是临时重定向或审查页面。

为什么?我想对用户在基于 GPS 的游戏中进入禁区进行处罚,该游戏根据用户的 GPS 数据显示某些网页。最后一部分工作正常。

搜索后我认为它可能适用于 PHP,但我对此的经验很少。我知道 HTML 和 CSS,以及如何阅读和修改现有的 JavaScript 和 PHP 脚本,而不知道如何从头开始构建这些代码。

另一种选择(我无法真正弄清楚)是让网站在有人进入页面时发送电子邮件,并让另一个服务,如“如果这样然后那样”使网站脱机/更改文件名。

4

2 回答 2

1

在你的 PHP 页面上,我会做这样的事情:

<?php
   if(!can_view_page()){
       header('Location: other_page.php');
   }
?>

can_view_page()功能中,您需要检查是否满足条件(例如在正确的位置查看页面)。

于 2012-10-24T15:57:51.973 回答
1

像其他回答者建议的那样,创建一个函数,您可以使用它来检查用户是否可以访问该页面的条件。这是一些混合使用 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.

于 2012-10-24T16:16:02.513 回答