PHP Random Image Generator
With all my designs, I go to great lengths to ensure total validation - either XHTML1 Transitional, or XHTML1 Strict. Handcrafted Webs was my last coded project. A very simple site, but done in XHTML1 Strict.
Problem came in when I wanted to have different images on each of the internal pages. In the past I’ve used a javascript random image code, but it doesn’t validate for a bunch of reasons too many to work through. The clever lads at A List Apart solved my problem with a much better PHP Random Image Generator that works a lot easier than the javascript option.
Essentially, your image src will be the PHP file that contains the script to generate a random image. So download the rotate.php script and then do the following:
- Create a folder to hold all the images you want to randomly rotate through. ie
/images/random/
- Save the rotate.php file inside the above folder. (you dont have to save it in here, but if you save it somewhere else, make the necessary changes inside the rotate.php file to indicate where the random image folder is located.
- Where you want the random image to display, make your image
src point to the rotate.php file
- Enjoy.
You can see it in action here.
Merry validated randomizing.
2 Responses to PHP Random Image Generator
Ya its a very cool script luke. Keeps things fresh and its so easy to just drop new images into the folder without having to update any code…
Leave a Reply