Authority Black Book

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

Tags: , ,




Thank you for reading this post. You can now Read Comments (2) or Leave A Trackback.

Post Info

This entry was posted on Thursday, September 25th, 2008 and is filed under Scripts.

You can follow any responses to this entry through the Comments Feed. You can Leave A Comment, or A Trackback.



Previous Post: Article Marketing and Internet Marketing for Instant Cash »
Next Post: Free Article Submission Software Delivers a Huge Volume of 1-way Links! »

Read More

Related Reading:

2 Responses to “Php Content Rotator

  • 1
    Douglas Wade
    October 16th, 2008 10:58

    Hey Scott,

    Thanks a bunch for this useful php image rotator script!

    Douglas Wade

  • 2
    scottparat
    October 16th, 2008 21:33

    Glad you like it Douglas…hope you can put the rotator script to good use.

    I create a demo page that rotates ads, images, banners, text and google adsense as a sample…check it out here http://www.spgraphic.com/image_rotator_test/

    Just keep hitting your refresh button on your browser to see how the images rotate, also you can see that I linked the images.

    Take care,

    Scott



Leave a Reply

Note: Any comments are permitted only because the site owner is letting you post, and any comments will be removed for any reason at the absolute discretion of the site owner.