Page 1 of 1

Rotate informations

Posted: Sat Jan 08, 2005 7:40 am
by poeta_eletrico
Hi,

I was imagining the best way to develop a kind of ROTATE TEXT INFORMATIONS AS FOLLOWS:
I place a single TXT file inside a dir called: ADVERTISE.
But I want to output this file as <? include("./advertise/text.txt")?> into my INDEX PAGE on the right col of my table.
All texts in TEXT FILE is separate by ";". So turning simple to use SPLIT to break in identifies each block text to display correctly on a give limit TIME.
All I want to do now is on every 5 min the code REFRESHES and take the next TEXT BLOCK as a BANNER ROTATOR.
I read some documents but did not find the best clue to finish this. Can anyone here give a "clue" to put me in the right path?

Thank You Very Much !
Kind Regards,
Poeta_Eletrico

Posted: Sat Jan 08, 2005 8:04 am
by potsed
put the output into an iframe, then use a meta page refresh pointing to the output page set for the time you want. The page it points to in the refresh should be somthing like http://www.pageToRefresh.php?ad=1, Then in the pageToRefresh.php, you simply use $_GET['ad'] to choose the next advert, and set the meta refresh tag to http://www.pageToRefresh.php?ad=2 so that the next ad shows and so on...

Posted: Sat Jan 08, 2005 8:06 am
by markl999
Here's another way too:

Code: Select all

define('ADFILE', 'advertise/text.txt');
define('ROTATIONTIME', 300); //every 5 minutes

//calculate the difference between current time and the adfile time
$timediff = time() - filemtime(ADFILE);

//get the ads
$ads = explode(';', file_get_contents(ADFILE));
$totalads = count($ads);

if($timediff > (ROTATIONTIME * $totalads)){
  //reset the rotation
  touch(ADFILE);
  $currentad = 1;
} else {
  //get the current advert
  $currentad = ceil($timediff / ROTATIONTIME);
}

//echo out the current advert
echo $ads[$currentad - 1];

Posted: Sat Jan 08, 2005 8:20 am
by potsed
To give a better example for my prev post...

the iframe code

Code: Select all

&lt;iframe src="http://www.example.com/pageToRefresh.php"&gt;&lt;/iframe&gt;
the pageToRefresh.php code

Code: Select all

<?php
$AD = ($_GET['ad']) ? $_GET['ad'] : 0;
$adverts = file("path/to/adverts.txt");
$currentAd = $adverts[$AD];
$nextAd = (array_key_exists(($AD+1), $adverts)) ? ($AD+1) : 0;
$refreshPage = "http://www.example.com/pageToRefresh.php?ad=".$nextAd;
?>
<html>
<head>
<meta http-equiv="refresh" content="300;url=<?PHP echo $refreshPage; ?>">
</head>
<body>
<?PHP echo $currentAd; ?>
</body>
</html>
have not tested this but it should work..

BTW Doing it this way each ad should be on a seperate line and there is no need to split it.