Sonam
Simple contnent rotator
This simple content rotator will rotate your content independent of day in the week. You need to create one separate folder where you will insert all your files with content (in my script I am give to this folder name conts - second line, but you can change it). Then insert in this folder current.txt file, too. Write in current.txt file (it must have only one line) your first display (e.g. some.php ). Also, in line 5 you can define the day of change - 0 (for Sunday) through 6 (for Saturday).
Note:
Script will grab any type of files (subfolders and current.txt are excluded) what mean you can use txt, htm, html, php, asp or some other extension. You can put images in this files, too, but you cannot include images directly.
Good luck
Here is script:
| Code: |
| <?php
$dir = "partners"; // dir where are files $date = date("w"); // looking for day in the week $current = file($dir . "/current.txt"); // txt file where is writen datas $changes = 3; // 0 (for Sunday) through 6 (for Saturday) $trigger = date("z"); // check the day in the year (0 through 365) list($currentInc, $currentDay) = explode("|", $current['0']); // read dir and create one array from files if($date == $changes && $trigger != $currentDay) { $openDir = opendir($dir); while (false !== ($fileNames = readdir($openDir))) { if($fileNames == "." || $fileNames == ".." || $fileNames == "current.txt") { continue; } else { $allfiles[] = $fileNames; } } // looking for position in array of current display $key = array_search($currentInc, $allfiles); if($key === FALSE) { $newKey = 0; } else { $newKey = $key + 1; } $count = count($allfiles); // count all files and define new one if($newKey > $count-1) { $newCurrent = $allfiles['0'] . "|" . $trigger; $display = $allfiles['0']; } else { $newCurrent = $allfiles[$newKey] . "|" . $trigger; $display = $allfiles[$newKey]; } // write new one display in current.txt $newData = fopen($dir . "/current.txt", "wb"); fwrite($newData, $newCurrent); fclose($newData); // include right file include_once($dir . "/" . $display); exit; } else { // if is not time for change include file from current.txt include_once($dir . "/" . $currentInc); } ?> |
2 blog comments below
Oooopsss, I am make one mistake in this script. I will solve this next year.
Sonam
Sonam
sonam on Mon Dec 31, 2007 3:40 pm
Ok,
problem is solved. Now, create empty current.txt in your chosen folder. Chmod 666 on Linux, Unix servers and run rotator.php script. Script will chose and display your first include file (sorted by name) and write this data in current.txt.
Note:
For first run you must chose right current day in the week (rotator.php - line 5). For example, for today right chose is 3. Ones you are run script you can change this on any other day for future changes.
Sonam
problem is solved. Now, create empty current.txt in your chosen folder. Chmod 666 on Linux, Unix servers and run rotator.php script. Script will chose and display your first include file (sorted by name) and write this data in current.txt.
Note:
For first run you must chose right current day in the week (rotator.php - line 5). For example, for today right chose is 3. Ones you are run script you can change this on any other day for future changes.
Sonam
sonam on Wed Jan 02, 2008 4:48 pm