我如何根据时间加载2个不同的页面


how do i load 2 different pages depending on the time?

我有两个不同的索引页

我需要在6:00-18:00之间加载一个,在18:00-6:00之间加载第二个。

我该如何在php中做到这一点?

<?
$hour = (int)date("H");
if($hour >= 6 && $hour < 18)
    include "index1.php";
else
    include "index2.php";
?>

PHP date()也很有用

更新:添加演员int

像这样:

<?php
    $hour = localtime(time(), true)["tm_hour"];
    if ($hour >= 6 && $hour < 18) {
        include "daytime.php";
    } else {
        include "nighttime.php";
    }
?>