Web development tip - Showing different image for each day of the week in our sites

Web development tip - Showing different image for each day of the week in our sites

We can display different images in our site by using the following script.

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

Example

<?php

/*
* Note : Image names must be like Monday.gif, Tuesday.gif etc
*/

// Specify the location of the directory, where we can have our images
$image_dir = “images/dayimage”;

// Fetch image name from date() function

$today_img = date(’l');

if (file_exists($image_dir.”/”.$today_img.”.gif”)) {
echo “<img src=\”$image_dir/”.$today_img.”.gif\”>”;}
?>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.