Archive for November, 2011

Random Rotation of Images Using PHP and Not Javascript

Wednesday, November 30th, 2011

I am not really against javascript but I do prefer to not use it when I can do the same with other coding methods like html, css and php.  There are a lot of scripts and examples to enable the random loading of an image each time a page loads, however most of them use javascript.  While they work, they relied not only on javascript but also that the viewer of the page was running javascript. Many people turn javascript off for fear of being hacked, hijacked or something else, which for 99.9% of the time will not happen, but paranoia is there with quite a few ;).

I am still relatively new to php, but I am learning the more I play with it.  While learning I came across the rand function which gave me some ideas when combining it with an echo.  Could I use php to look for images in a folder, randomly select one of them and then display it.  It sure could and it is very easy to do, you can do it as an ‘img src’ or even css background. (more…)