Different background for each day of the week using php.

By mcvanrensburg  | 

 November 25th, 2011 | 

For those of you familiar with basic php and the date function, here is a very simple trick to change the background of your website to correspond with each day of the week. Now even your website can be blue on monday’s!


First of all, for this trick I will use the date(“w”) function. Remember, this function returns a day of the week in numerical form. Thus if today is Friday, it will return a 5. (Friday is the 5th day of the week)


So if you do the following,


<body background="background_<?php echo date("w"); ?>.jpg">



you dynamically change the background to correspond with each day of the week. This is achieved by naming your background images to background_1.jpg,background_2.jpg,background_3.jpg etc, so that each day will have a different background.


This is a very simple example of how a very simple line of php can spice up your website.


Note that you must be working on a server that supports php, otherwise this will not work.



Be Sociable, Share!

    Leave a Comment