Php Content Rotator
I found myself helping someone that needed a script the rotated content. In this case he needed a php script to rotate images. I gave him the below information for a php content rotator
Here is an example of the below php rotater script in action.
Hey Dave
I made some minor changes to a script Robert Plank posted on the warrior forum. You can use it to rotate anything but I use it to rotate images.
First use the below code and create a page called images.php
<?php
$hash = floor(time() / (60*60*24));
//srand($hash);$images = array_map(“trim”, file(“images.txt”));
$image = $images[array_rand($images)];
echo $image;?>
If you remove the two // before the line strand($hash); the images will rotate on a 24 hour basis, otherwise as it is, it will rotate images on page reload on a random basis.
Remember to upload the above file and save as images.php
Next create a text file called images.txt and add each image on a seperate line. It would look something like this:
<img src=”rightclick.jpg”>
<img src=”horse.jpg”>
<img src=”banner2.jpg”>
<a href=”http://www.spgraphic.com” target=”_blank”><img src=”rightclick.jpg” alt=”graphics”></a>
Note:
On the last line the image is linked to a website and set to open in a new page.
Remember—-> upload and and save the file as images.txt
Next you will want to get an individual image to show on your webpage:
You can use the below php include to bring the image into your webpage. Your pages must have a .php extension to make this work.
<?php require(“images.php”); ?>
OR
You can add a couple lines of code to your .htaccess file which will allow your pages to stay .htm or .html and still process the php code. If you don’t know how to do this you should contact your hosting provider and ask them what code you should use.
ANOTHER WAY
Another way to keep your page extensions as .htm or .html is to use an iframe to bring your images in. You must make sure you change the iframe dimensions to match your image dimensions. For instance if you had a 468 x 60 banner you would want to change to iframe dimensions to 470 x 62…..you might need to experiment to ensure the scroll bar doesn’t show up in the iframe.
PHP INCLUDE
<?php require(“images.php”); ?>
IFRAME
<iframe src=”images.php” width=”300″ height=”100″></iframe>
Don’t be afraid to use php includes or experiment with php code. If you can get it to work it becomes addicting! I’ve learned a lot from Robert Plank, you can check out his blog at PlanksBlog ….it’s packed with good stuff
Hope this php content rotator helps you with your client.
You can see how this script rotates content by clicking on that link, there are 3 images that are linked and rotated, the script is configured to rotate random images.
Good luck
Scott











