website script?
Discussion
Is there such a script that can do this? Basically all i want to do is serve a certain webpage at certain times of the day, at other times a different webpage would be served, the URL that points to these pages would remain the same though? The script would need to get the time of day from the server. Any ideas?
You could do a time based redirection with htaccess, but that would depend on the time of the server clock.
Do you need the page to be customised depending on the end users time or the time on the server?
{{{ Time Based Redirection
RewriteEngine on
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0100
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1200
RewriteRule ^.*$ http://www.blah.com/themorning.html
}}}
Something like this???
Hmm the code tags don't work!
Do you need the page to be customised depending on the end users time or the time on the server?
{{{ Time Based Redirection
RewriteEngine on
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0100
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1200
RewriteRule ^.*$ http://www.blah.com/themorning.html
}}}
Something like this???
Hmm the code tags don't work!
Edited by ad551 on Friday 23 October 12:51
Edited by ad551 on Friday 23 October 12:52
Just wrote this quickly, before I saw your post, this will do before & after 12 and then after 5.
4.30 makes it slightly more complex, give me 5 mins.
{{{
<?php
date_default_timezone_set('Europe/London');
$inc_file = "";
$hournow = date('G');
switch ($hournow) {
case ($hournow < 12):
$inc_file = "morning.html";
break;
case ($hournow >= 12 && $hournow < 17):
$inc_file = "afternoon.html";
break;
case ($hournow >= 17):
$inc_file = "evening.html";
break;
}
require_once($inc_file);
?>
}}}
ETA - How the fk do you do code tags?
4.30 makes it slightly more complex, give me 5 mins.
{{{
<?php
date_default_timezone_set('Europe/London');
$inc_file = "";
$hournow = date('G');
switch ($hournow) {
case ($hournow < 12):
$inc_file = "morning.html";
break;
case ($hournow >= 12 && $hournow < 17):
$inc_file = "afternoon.html";
break;
case ($hournow >= 17):
$inc_file = "evening.html";
break;
}
require_once($inc_file);
?>
}}}
ETA - How the fk do you do code tags?
Edited by crb on Friday 23 October 12:58
<?php
date_default_timezone_set('Europe/London');
$inc_file = "";
$minsnow = (date('G')*60)+(date('i'));
switch ($minsnow) {
case ($minsnow < 720):
$inc_file = "morning.html";
break;
case ($minsnow >= 720 && $minsnow < 990):
$inc_file = "afternoon.html";
break;
case ($minsnow >= 990):
$inc_file = "evening.html";
break;
}
require_once($inc_file);
?>
That'll work, basically save this code in the in a file named whatever.php then set up your 3 different html files (morning.html, afternoon.html and evening.html) the url you always link to will always be whatever.php
The first line sets the timezone to the uk and wouldn't be needed if your server is in the UK (mine isn't), but if someone is visiting from abroad it will be off, if this is an issue, I could probably find away round it.
date_default_timezone_set('Europe/London');
$inc_file = "";
$minsnow = (date('G')*60)+(date('i'));
switch ($minsnow) {
case ($minsnow < 720):
$inc_file = "morning.html";
break;
case ($minsnow >= 720 && $minsnow < 990):
$inc_file = "afternoon.html";
break;
case ($minsnow >= 990):
$inc_file = "evening.html";
break;
}
require_once($inc_file);
?>
That'll work, basically save this code in the in a file named whatever.php then set up your 3 different html files (morning.html, afternoon.html and evening.html) the url you always link to will always be whatever.php
The first line sets the timezone to the uk and wouldn't be needed if your server is in the UK (mine isn't), but if someone is visiting from abroad it will be off, if this is an issue, I could probably find away round it.
Edited by crb on Friday 23 October 13:05
Dave_ST220 said:
Basically up until midday i need one page to be served, after midday another page & at 4.30pm a final page. Cron? Wasn't that a film??!! Oh no, that was Tron....
You have a linux / unix based server and don't know what cron is? Who administers it for you? They should know.crb said:
<?php
date_default_timezone_set('Europe/London');
$inc_file = "";
$minsnow = (date('G')*60)+(date('i'));
switch ($minsnow) {
case ($minsnow < 720):
$inc_file = "morning.html";
break;
case ($minsnow >= 720 && $minsnow < 990):
$inc_file = "afternoon.html";
break;
case ($minsnow >= 990):
$inc_file = "evening.html";
break;
}
require_once($inc_file);
?>
That'll work, basically save this code in the in a file named whatever.php then set up your 3 different html files (morning.html, afternoon.html and evening.html) the url you always link to will always be whatever.php
The first line sets the timezone to the uk and wouldn't be needed if your server is in the UK (mine isn't), but if someone is visiting from abroad it will be off, if this is an issue, I could probably find away round it.
Works a treat m8 Many thanks for your help.date_default_timezone_set('Europe/London');
$inc_file = "";
$minsnow = (date('G')*60)+(date('i'));
switch ($minsnow) {
case ($minsnow < 720):
$inc_file = "morning.html";
break;
case ($minsnow >= 720 && $minsnow < 990):
$inc_file = "afternoon.html";
break;
case ($minsnow >= 990):
$inc_file = "evening.html";
break;
}
require_once($inc_file);
?>
That'll work, basically save this code in the in a file named whatever.php then set up your 3 different html files (morning.html, afternoon.html and evening.html) the url you always link to will always be whatever.php
The first line sets the timezone to the uk and wouldn't be needed if your server is in the UK (mine isn't), but if someone is visiting from abroad it will be off, if this is an issue, I could probably find away round it.
Edited by crb on Friday 23 October 13:05
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff