View Full Version : Time Based Page Redirection
webhost
05-02-2003, 06:09 PM
We have a contact us page with online/open times and other information.
We would like to also have a page that is somewhat different from the online page lets call it offline page.
How would one use a php statement based on server time to have it automatically switch between pages?
Black Vivi
05-02-2003, 07:43 PM
try this:
$hour = date("G");
if ($hour < /* OFFLINE PAGE HOUR */) {
/* OFFLINE PAGE */
} else {
/* ONLINE PAGE */
}
replace what's in the block quotes with whatever you want.
so, an example of a page would be:
$hour = date("G");
if ($hour < 18 || $hour > 6) {
echo("We are currently offline!");
} else {
echo("We are currently online!");
}
webhost
05-02-2003, 07:55 PM
We want the time to switch between say contacton.html and contactoff.html
Black Vivi
05-02-2003, 09:18 PM
what times do you want it to display "contactoff.html"?
then ill just give u the code.
webhost
05-02-2003, 09:36 PM
http://www.realwebhost.net.contact.php = online
12:00 pm to 6:00 pm
http://www.realwebhost.net/contact1.php = offline
6:00pm to 12:00 pm
has to be hours and minutes not just hours are there will a hour delay
webhost
05-02-2003, 09:53 PM
This is what we have in contact.php
<?php
// the online time will be from 14 to 16:59
// taking minutes into consideration was
// more trouble
/// so $onlineuntil should be realend - 1
$onlinefrom = 12; // in hours
$onlineuntil = 18; // in hours
// $date holds the current HH
$date = date('H', time());
if ( ! ($onlinefrom <= $date && $date <= $onlineuntil) ) {
header("Location: http://www.realwebhost.net/contact1.php");
}
?>
This what we have in contact1.php
<?php
// the online time will be from 14 to 16:59
// taking minutes into consideration was
// more trouble
/// so $onlineuntil should be realend - 1
$onlinefrom = 18; // in hours
$onlineuntil = 12; // in hours
// $date holds the current HH
$date = date('H', time());
if ($onlinefrom <= $date && $date <= $onlineuntil) {
header("Location: http://www.realwebhost.net/contact.php");
}
?>
But it does not work.
Black Vivi
05-03-2003, 06:29 AM
try this:
contact.php
<?php
// the online time will be from 14 to 16:59
// taking minutes into consideration was
// more trouble
/// so $onlineuntil should be realend - 1
$onlinefrom = "14:00"; // in hours
$onlineuntil = "16:59"; // in hours
// $date holds the current HH
$date = date("G:i");
if ($onlinefrom >= $date || $date >= $onlineuntil) {
header("Location: contact1.php");
}
?>
and this for contact1.php
<?php
// the online time will be from 14 to 16:59
// taking minutes into consideration was
// more trouble
/// so $onlineuntil should be realend - 1
$onlinefrom = "14:00"; // in hours
$onlineuntil = "11:59"; // in hours
// $date holds the current HH
$date = date("G:i");
if ($onlinefrom <= $date || $date >= $onlineuntil) {
header("Location: contact.php");
}
?>
webhost
05-03-2003, 11:32 AM
Thank you very much, we will try it. We last nite when what we had did not work went with 2 files and 2 perl scripts and run them from cron.But we will try this.
Thank You for your effort.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.