Many thanks to Mr Zeldman for sharing the random image script I put together. (Twice in about a week, I’m starting to blush.) Shortly afterwords Charles Dietlein (who also has one) dropped an email suggesting that I seed the random number picker for users of old PHP distributions. Done, and thank you for the heads up. I still believe that letting the web server do the grunt work is the most elegant method available.
I have received several questions asking how the individual images may be cached but it still “rotates” on every reload. Well, it’s all in HTTP. The response from the PHP script is never cached because it sends a
302 Temporary Redirect header, which by specification should not be cached by the browser or caching servers. The images themselves, once served, are just like any other static file, and they are server with Etags and
Last-Modified headers that allows a browser to check later if anything has changed. If the browser receives a
304 Not Changed header in response, it knows it can go on its merry way and return the image from cache. There you have it.