Reputation: 1
I am trying for Time Based Image Swaping by using this following PHP Script, but is not functioning properly as the image 'night.jpg' getting into effect by 17:00 hrs and the image 'morning.jpg' is not appearing, at all. Please help me out to resolve this issue. The code which I am using for the purpose is as follows:-
<?php
date_default_timezone_set("Asia/Kolkata");
$hour= date('G');
if($hour > 5 && $hour < 7){
echo '<img src="morning.jpg">';
}
else if($hour > 7 && $hour < 12){
echo '<img src="day.jpg">';
}
else if($hour > 12 && $hour < 17){
echo '<img src="noon.jpg">';
}
else if($hour > 17 && $hour < 19){
echo '<img src="evening.jpg">';
}
else{
echo '<img src="night.jpg">';
}
?>
Upvotes: 0
Views: 280
Reputation: 2530
As stated in the comment by @xeraphim, your if
conditions aren't correct, if we read your code it does the following:
If you want to get the right conditions, change your >
symbols by >=
Upvotes: 1