简体   繁体   English

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

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

I have two different index pages. 我有两个不同的索引页。

I need to load one between 6:00-18:00 hrs and the second at 18:00-6:00 hrs. 我需要在6:00-18:00之间加载一个,在18:00-6:00加载第二个。

How would I do this with php? 我将如何用php做到这一点?

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

Also PHP date() is useful for your needs 另外, PHP date()可以满足您的需求

Update: Added cast to int 更新:将强制转换添加到int

Something like this: 像这样:

<?php
    $hour = localtime(time(), true)["tm_hour"];

    if ($hour >= 6 && $hour < 18) {
        include "daytime.php";
    } else {
        include "nighttime.php";
    }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM