Log in

View Full Version : Time based Changing content



pankajt
06-02-2008, 05:46 PM
Hi Guys,

I am a newbie to php and I have a complicated query.....I have a index.php page and.....inside it I use <?php include("LinksBar.php"); ?> to include the LinksBar file which is a html table with few links........

Now I want to change this Linkbar file with time....I mean in morning the index.php uses a morning LinksBar.php and other in afternoon and next in evening and so on and so forth.....

I have seen some posts in this forum where they tell u to redirect the whole page.......Can anybody tell me how I use <?php include("LinksBar.php"); ?> this to change every hour???

Thanx In Advance
pankajt

Jas
06-02-2008, 06:18 PM
Take a look at this:


<?php
$time = date('H');
if($time < 12){
echo 'good morning';
}else if($time >= 12 and $time < 18){
echo 'good afternoon';
}else{
echo 'good evening';
}
?>

pankajt
06-03-2008, 04:59 AM
Thanx Jas 4 ur reply.....but I am still confused...shall I replace echo 'good morning'; with <?php include("LinksBar.php"); ?> ????

or shud I write as include("LinksBar.php") only...plz tell..
TIA
pankajt

codeexploiter
06-03-2008, 05:45 AM
Now I want to change this Linkbar file with time....I mean in morning the index.php uses a morning LinksBar.php and other in afternoon and next in evening and so on and so forth.....

I feel that instead of including a different file based on the time you can have PHP code that works with different time. So you need to include only one file but the code inside the included file will act based on the timing.

pankajt
06-03-2008, 12:39 PM
No no...actually I have a page and this links file...gives a table with links which open in an iframe....now I wanna change this file with time so that the target frame show different pages with time......

hope I was able to eplain..what Iwant

Jas
06-03-2008, 04:06 PM
Change the echo statements to include statements. For example:


<?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
//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.

pankajt
06-03-2008, 06:26 PM
Thanx a lot Jas ...The script look Good ( I haven't tested yet.....) but whatever little I know its gonna work....Thanx again :-) :)

Budde
07-21-2008, 07:14 PM
I'd like to make a specific piece of code show up at a specific time on Specific days.

Such as Monday, Tuesday, Wednesday and Fridays at 4PM EST

Such as every other Friday at 7PM EST

Such as on Fridays at 8PM EST

and so on... I can modify it once I see the code to make it work for other dates/times.

Thanks in advanced... Josh