Advanced Search

Results 1 to 8 of 8

Thread: Time based Changing content

  1. #1
    Join Date
    Jun 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Time based Changing content

    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

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Take a look at this:
    PHP Code:
    <?php
    $time 
    date('H');
    if(
    $time 12){
       echo 
    'good morning';
    }else if(
    $time >= 12 and $time 18){
        echo 
    'good afternoon';
    }else{
        echo 
    'good evening';
    }
    ?>
    Last edited by Jas; 06-02-2008 at 06:24 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Jun 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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.

  5. #5
    Join Date
    Jun 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  6. #6
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    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.
    Last edited by Jas; 06-03-2008 at 04:12 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. #7
    Join Date
    Jun 2008
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanx a lot Jas ...The script look Good ( I haven't tested yet.....) but whatever little I know its gonna work....Thanx again :-)

  8. #8
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •