Here is a great php tip for those who want to load a different image into your header every time the page loads. For example, you may have a folder of images that you want to rotate in your header or any element of your site for that matter. Here’s how to do it.

Place all your images in a folder and name them something like this:

  • pics/image1.jpg
  • pics/image2.jpg
  • pics/image3.jpg

Use the php rand() function to give your header an random id.

<div id="header<?php echo rand(1,3); ?>">
<!-- header content here --></div>

The rand function in the code above returns a random number between 1 and 3 which is what we want. So every time the page is loaded, we get an id of either header1, header2 or header3. In you CSS you can now markup like this.

DIV#header1 {background-image:url("pics/image1.jpg")}
DIV#header2 {background-image:url("pics/image2.jpg")}
DIV#header3 {background-image:url("pics/image3.jpg")}

Now your page loads with a random header image. Brilliant!