我正在尝试为我的论坛软件(vBulletin 3.x,通过 Hook 系统支持 PHP 例程)设计一个小例程。我从之前所做的一些研究中得到了这段代码,但条件并没有按照我的预期运行 - 只有当开始时间设置为 0000 或更高时,它才会为“true”。
$regtime = gmdate('Hi');
$pnr_b1 = "2300";
$pnr_b2 = "0600";
if ($regtime > $pnr_b1 && $regtime < $pnr_b2) {
// prevent registration code
}
有人可以帮忙吗?作为引用,我正在运行 PHP 版本 5.3.29,以防影响您的建议。
最佳答案
除了比较字符串之外,您还可以使用 DateTime
对象,以便轻松比较时间:
$regtime = new DateTime('23:15');
$from_time = new DateTime('23:00');
$to_time = new DateTime('23:30');
if($regtime >= $from_time && $regtime <= $to_time) {
echo 'okay, process this';
} else {
echo 'not allowed';
}
关于php - 防止在特定时间之间注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27307168/