jump to navigation

Display a different image for each day of the week with PHP January 7, 2011

Posted by Tournas Dimitrios in Linux.

This PHP script will get the day of the week from the server date and then display an image (jpg or gif) to match.

The code :


 * Change the name of the image folder


 * Images must be named Monday.gif, Tuesday.gif etc


// Change to the location of the folder containing the images

$image_folder = "images/days";

// You do not need to edit below this line

$today = date('l');

if (file_exists($image_folder."/".$today.".gif")) {

  echo "<img src=\"$image_folder/".$today.".gif\">";


else {

  echo "No image was found for $today";



Visit my site to see this script in action . Well because my hosting server resides in the United States , it will reflect the server’s  date  . So a visitor from Japan will get a day that reflects the US time and not his local time  . To overcome this time zone gap we have to implement  timezone offset with JavaScript.


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s