Change the echo statements to include statements. For example:
PHP Code:
<?php
$time = date('H');
if($time < 12){
include("morning.php");
}else if($time >= 12 and $time < 18){
include('afternoon.php');
}else{
include('evening.php');
}
?>
To explain the code:
PHP Code:
<?php
//Get the current hour (1-24)
$time = date('H');
//If the time is before noon, it's morning
if($time < 12){
//include the morning file
include("morning.php");
//if the time is after 12pm but before 6pm, it's the afternoon
}else if($time >= 12 and $time < 18){
//include the afternoon file
include('afternoon.php');
//otherwise, it must be nighttime
}else{
//include the evening file
include('evening.php');
}
?>
A note, however: This is the server's time, not the user's time. So, if the server is in NY and the time is seven, the include will be evening.php, regardless of where the user is.
Bookmarks