PHP Code Share – Random, part 2

Before I forget again I want to throw in the disclaimer that I am not a developer and have just found some pretty good scripts to use for my own site purposes.  I make no claims about their security or anything else.  So if for some reason you use any of this code and hackers use your website to get into Dubya’s personal White House email, don’t point the feds this way when they come knockin’ at your door. LOL

Okay with that out of the way, here is another random image php script I use.  It’s also pretty simple, and could easily be swapped out for the last one I posted.  But I always think options are a good thing.  Just take a look at any of my over 20 pairs of shoes (mostly Skechers).  Here is the code:
<?php

/*

* Name your images 1.jpg, 2.jpg etc.

*

* Add this line to your page where you want the images to

* appear: <?php include “randomimage.php”; ?>

*/

// Change this to the total number of images in the folder

$total = “7”;

// Change to the type of files to use eg. .jpg or .gif

$file_type = “.jpg”;

// Change to the location of the folder containing the images

$image_folder = “images/random”;

// You do not need to edit below this line

$start = “1”;

$random = mt_rand($start, $total);

$image_name = $random . $file_type;

echo “<img src=”$image_folder/$image_name” alt=”alt text here” style=”border: #cccccc 1px solid” />”;

?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Verification *

This site uses Akismet to reduce spam. Learn how your comment data is processed.