Possibly simple PHP solution?

Discussion in 'PHP' started by necromancer1976, Jul 1, 2008.

  1. #1
    I have a PHP script that has a link in it. I need this link to be switched out with another one every 2 hours or given amount of time, then switched to the next one. Is it possible?
     
    necromancer1976, Jul 1, 2008 IP
  2. Varreon

    Varreon Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes. You should retrieve the time, and find what hour it is. Then, it would look something like this:
    if($hour>6)
    print $links[1];
    else if($hour>4)
    print $links[2];
    else if($hour>2)
    print $links[3];
    else
    print $links[4];

    This is just to give you an idea of how it would work.
     
    Varreon, Jul 1, 2008 IP
  3. AliasXNeo

    AliasXNeo Banned

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You'll need to store the time somewhere, possibly a Unix Time stamp to make things easy. Basically every time the link is changed you store the current Unix Time stamp somewhere and then refer to that time stamp to see how many hours have passed:

    $timeStamp = get_file_contents("timestamp.txt"); // assuming you store it in a text file
    if ((time() - $timeStamp) / 3600 > 2) // Unix Time Stamps are in seconds, divide by 3600 to get hours
    {
        // Link needs to be changed, do so here //
        file_put_contents("timestamp.txt", time()); // Store the new timestamp
    }
    PHP:
     
    AliasXNeo, Jul 1, 2008 IP