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