website script?

Author
Discussion

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
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?

JohnnyPanic

1,282 posts

210 months

Friday 23rd October 2009
quotequote all
Should be pretty easy, the best way would be a server side script - e.g. PHP or ASP.

What type of server are you on? Windows / Linux..?

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
Linux i think?? We have PHP running on it i know for sure. I know bugger all about these things, i can do basic webpages but nothing like this!! Thanks

JohnnyPanic

1,282 posts

210 months

Friday 23rd October 2009
quotequote all
I'm a Microsoft man for my sins, so sadly I know bugger all about Linux & PHP!

It should be perfectly doable, and I'm sure someone who knows this stuff will be along soon to point you in the right direction.

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
Thanks anyway, i did a quick search last night on Google but found nothing. Be good if it can be done smile

onomatopoeia

3,472 posts

218 months

Friday 23rd October 2009
quotequote all
Why not just write two shell scripts and invoke them with cron at different times to copy the appropriate version of the file to the required location?

crb

2,447 posts

198 months

Friday 23rd October 2009
quotequote all
I could knock something together for you it, how many intervals do you want and at what times?

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
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....

biggrin

ad551

1,502 posts

214 months

Friday 23rd October 2009
quotequote all
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!

Edited by ad551 on Friday 23 October 12:51


Edited by ad551 on Friday 23 October 12:52

ChrisMCoupe

927 posts

213 months

Friday 23rd October 2009
quotequote all
Cron is a Unix based scheduler that can run any kind of shell script, which I beleive you could use to swap between which page is being read and at specified times of the day.

Edited by ChrisMCoupe on Friday 23 October 12:50

crb

2,447 posts

198 months

Friday 23rd October 2009
quotequote all
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?



Edited by crb on Friday 23 October 12:58

GreenV8S

30,242 posts

285 months

Friday 23rd October 2009
quotequote all
As a last resort, if you are absolutely stuck on the server-side scripting, you could serve out a page that has client-side script in to redirect to the right page based on the time at the client.

crb

2,447 posts

198 months

Friday 23rd October 2009
quotequote all
<?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.


Edited by crb on Friday 23 October 13:05

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
Sorry for the delay, been busy all afternoon!! Many thanks for this guys, i'll give it a go in a mo smile I did think of htaccess this afternoon!! I need the pages to change according to the servers time not the client as that will stay fixed. Thanks again.

onomatopoeia

3,472 posts

218 months

Friday 23rd October 2009
quotequote all
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....

biggrin
You have a linux / unix based server and don't know what cron is? Who administers it for you? They should know.

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
It was a joke wink I know what cron is but have no idea how to use it. Reg1 administer the server, we just play with a website smile

JohnnyPanic

1,282 posts

210 months

Friday 23rd October 2009
quotequote all
CRon is Fantasy Football speak for Cristiano Ronaldo, and I thought Linux was suppose to be the cost effective option?!

confused

Dave_ST220

Original Poster:

10,302 posts

206 months

Friday 23rd October 2009
quotequote all
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.


Edited by crb on Friday 23 October 13:05
Works a treat m8 wink Many thanks for your help.