Random Background Images Using PHP on Page Refresh

Changing background images randomly adds interaction to a website. Just make sure that you keep the branding of your site. One method to do this is usingĀ php code.

The code below works by choosing the background image from a list of images in a directory. Once chosen, the image will be used in the CSS to set as the background image. Make sure that you put all of this code inside the <head> tag.

After this, use CSS to get the URL of the background image.

It works like the usual CSS code and you can modify it except for the php code for the URL of the background image.