Hi I'll give 15 points to the person who can find me a FAST rotating image script like http://www.arcadetap.com/b/rotate.php
I would like it to be as fast and simple as possible.
I would like it to be as fast and simple as possible.
<?
// Image Rotator Script
// By Alex Cline (http://alex.elementfx.com)
// Displays the next image in the array based on a cookie which stores the previous image
// If the cookie doesn't exist, the first image is shown.
// Create the array of images. This must contain the names of all the images.
$imgArray = array("image1.jpg", "image2.gif", "image.png");
// Path to where your images are stored
$hostDir = "http://www.somedomain.com/path/to/images/"; // Don't forget that ending '/'
$imgArraySize = count($imgArray); // Store the size of the array (starts at 1)
$imgToShow = 0; // We'll default to always show the first image.
// Check to see if the cookie has already been created.
if ($_COOKIE['imagerotate'] != "") {
// The cookie existed
$imgToShow = $_COOKIE['imagerotate'];
if($imgToShow + 1 >= $imgArraySize) {
// The image we were supposed to show next would have been out of bounds in the array.
$imgToShow = 0; // We'll show the first image
}
else // The image to be shown is not out of bounds.
$imgToShow++; // Increment the image counter
}
// Write the new cookie with the new image we are showing
setcookie ("imagerotate", $imgToShow, time()+1000);
//Print the image from the directory.
echo "<img src=\"".$hostDir.$imgArray[$imgToShow]."\" alt=\"An Image\" />";
?>
The_Magistrate said:Spartan Erik, your script doesn't rotate images... it randomizes images. I'm trying to write one in PHP using a cookie... gimme a few minutes.
Here ya go... crude, but effective. Requires you to add the image filenames into the array and specify the path.
P.S. If you could throw a few more than 15 point my way, it would be appreciated.
PHP:<? // Image Rotator Script // By Alex Cline (http://alex.elementfx.com) // Displays the next image in the array based on a cookie which stores the previous image // If the cookie doesn't exist, the first image is shown. // Create the array of images. This must contain the names of all the images. $imgArray = array("image1.jpg", "image2.gif", "image.png"); // Path to where your images are stored $hostDir = "http://www.somedomain.com/path/to/images/"; // Don't forget that ending '/' $imgArraySize = count($imgArray); // Store the size of the array (starts at 1) $imgToShow = 0; // We'll default to always show the first image. // Check to see if the cookie has already been created. if ($_COOKIE['imagerotate'] != "") { // The cookie existed $imgToShow = $_COOKIE['imagerotate']; if($imgToShow + 1 >= $imgArraySize) { // The image we were supposed to show next would have been out of bounds in the array. $imgToShow = 0; // We'll show the first image } else // The image to be shown is not out of bounds. $imgToShow++; // Increment the image counter } // Write the new cookie with the new image we are showing setcookie ("imagerotate", $imgToShow, time()+1000); //Print the image from the directory. echo "<img src=\"".$hostDir.$imgArray[$imgToShow]."\" alt=\"An Image\" />"; ?>