The Yellow Llama | Web Design South Africa

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:

  1. Create a folder to hold all the images you want to randomly rotate through. ie /images/random/
  2. 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.
  3. Where you want the random image to display, make your image src point to the rotate.php file
  4. Enjoy.

You can see it in action here.

Merry validated randomizing.

2 Responses to PHP Random Image Generator

  • Written by: MarkB
  • Date: October 25th, 2006
  • Time: 11:33 pm

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



Blog News & Articles

What’s being loaded into this plane?

Its a hard disk in 1956.... HDD with 5MB storage in 1956. In September 1956 IBM launched the 305 RAMAC, the first computer with a hard disk drive (HDD). The HDD weighed over a ton and stored 5MB of data. Start appreciating your 1 GB memory ...

The WordPress Guru is launched

For the last 4 or 5 years that I've been using WordPress, I've managed to pick up a good few tips and tricks. 90% of my clients are sites who require content management systems, not blogs. And thus I've been able to create highly tweaked ...

A blind man wanders into an all-girls biker bar by mistake…

A blind man wanders into an all-girls biker bar by mistake. He finds his way to a bar stool and orders some coffee. After sitting there for awhile, he yells to the waiter, 'Hey, you want to hear a blonde joke? The bar immediately falls absolutely silent. ...

Looking for trouble…

Best part is when the dog looks up at the cat like... WTF are you doing...

26 Reasons why dogs bite people

...

Examples of Kulula attendants’ sense of humor

Kulula is an Airline with head office situated in Johannesburg. Kulula airline attendants make an effort to make the in-flight "safety lecture" and announcements a bit more entertaining. Here are some Real examples that have been heard or reported: On a Kulula flight, (there is no assigned seating, ...

News From Around