text link rotating php script ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
the_chancellor
Forum Newbie
Posts: 2
Joined: Mon Mar 20, 2006 4:33 pm

text link rotating php script ?

Post by the_chancellor »

Greetings,
I have been searching for a php script. Let me explain below ;

I have several text links (urls) to be rotated on my site. The script should rotate those links automatically accoring to my hosting service's server time. For instance, the text link on my site will be http://www.yahoo.com between 00am to 03am, and then will turn to http://www.google.com between 03am to 1pm, and then will turn to http://www.devnetwork.com between 1pm to 8:30pm, and will turn to http://www.phpbb.com between 8:30pm to 00am ..... etc. Let me tell you onces again that the time is "SERVER TIME".

Could anyone help me about this script? Is it too custom or can i find an anonymous script on the net?

Thank you all.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

its actually pretty simple, using something like

Code: Select all

switch (date('G', time()) {
   case '00' :
      echo $link1;      
      break;
   case '01' :
      echo $link2;
      break;
}
or

Code: Select all

$links = array(
   '00' => array('Yahoo' => 'http://yahoo.com'),
   '01' => array('Google' => 'http://google.com')
);

$hour = date('G', time());

if (array_key_exists($hour, $links)) {
   echo '<a href="'.$links[$hour][0].'">'.$links[$hour][1].'</a>';
}

you could of course make it a little more dynamic, but that should get you started ;)
User avatar
the_chancellor
Forum Newbie
Posts: 2
Joined: Mon Mar 20, 2006 4:33 pm

Post by the_chancellor »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thank you for your quick response Jcart:

I modified your first script like below. Is that correct? And if i dont bother you, i want to ask few more question. Those are :
* Should i insert (copy and paste) this code to a php page like "favoritelinks.php"?  but not a html?
* And the time 14:30 and 21:45 are okay? Thank you again?

Code: Select all

<?php
switch (date('G', time()) { 
   case '00' : 
      echo $http://www.yahoo.com;       
      break; 
   case '03' : 
      echo $http://www.google.com; 
      break; 
   case '14:30' : 
      echo $http://www.devnetwork.net;       
      break; 
   case '21:45' : 
      echo $http://www.phpbb.com; 
      break; 			
}  
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply