Display certain image depending on time of year


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I am new to these forums and would really appreciate some advice on a piece of coding I have done.

Basically what I am trying to do is on our intranet, display a different home page banner depending on the time of the year. For example, display a halloween banner for halloween. So this is the code I have put in to do the trick but as I am no expert on PHP I was wondering if there was an easier way of doing it.

$currday = date('d'); // gets the current day of the year
$currmonth = date('m'); // gets the current month of the year

if ($currmonth == '09') { // if in October, display Halloween banner
if ($currday >= '12' && $currday <='31') {
echo "<img src='images/buttons_banners/newsbar_banner_halloween.jpg' alt='Happy Halloween'/>";
} else {
echo "<img src='images/buttons_banners/newsbar_banner_staff.jpg' alt='Welcome'/>";
}
} elseif ($currmonth == '11') { // if in November, display bonfire night banner
if ($currday >= '03' && $currday <='05') {
echo "<img src='images/buttons_banners/newsbar_banner_bonfire.jpg' alt='remember remember'/>";
} else {
echo "<img src='images/buttons_banners/newsbar_banner_staff.jpg' alt='Welcome'/>";
}
} elseif ($currmonth == '12') { // if in December, display xmas banner
if ($currday >= '01' && $currday <='31') {
echo "<img src='images/buttons_banners/newsbar_banner_xmas.jpg' alt='Merry Christmas'/>";
} else {
echo "<img src='images/buttons_banners/newsbar_banner_staff.jpg' alt='Welcome'/>";
}
} else { // anything else, display default banner
echo "<img src='images/buttons_banners/newsbar_banner_staff.jpg' alt='Welcome'/>";
}

Any help would be appreciated.

No comments posted yet

Your Answer:

Login to answer
192 Like 18 Dislike
Previous forums Next forums
Other forums

PHP page loading in Firefox but not in IE
hello,

i am currently doing a project in PHP and i have a problem. If I view the project in M

Including calander to page - will not show other months than current??
im trying to add an existaing calander onto a profile page by using Code: <?php include "

smart reading from a text file
Hello there fellow coders, i was wondering if one of you wouldnt mind helping me with this problem i

I need some help with the IF command...
I have a large number of images in one section of my website with the .jpg format. I'm adding a bun

Check Date/Time in PHP
What I need the code to check is that $reQuest is 24 hours in the past then return a time based on h

BB_Code error
I'm having a problem with a custom built function and keep getting this error:


Warning: M

PHP Session Issue
I'm having an issue with one section on my website dealing with sessions. Now I know that myself and

Printing a webpage
I use this to print the webpage: o

keeps going back to index.html ???????
ok so i started making my site using mostly.html files now i have added a fair chunk of php. My inde

What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash