PDA

View Full Version : Image change with time



PartyRing
28-08-2007, 05:24 PM
Ive got this php code which changes an image at a specific server time:


<?php
$timeOffset = + 0; // in hours, positive or negative
$nowHour = date("H", time() + (3600 * $timeOffset)) ;

if ($nowHour >= 16 && $nowHour < 0)
$message = '<img src="image1">';
else if ($nowHour >= 0 && $nowHour < 6)
$message = '<img src="image2">';
else if ($nowHour >= 6 && $nowHour < 17)
$message = '<img src="image3">';
else $message = '<img src="otherimage">';
print($message);

?>

And it works, i think, but theres a time problem, can anyone help or work out whats wrong? :(

Drompo
28-08-2007, 06:04 PM
<?php
$time = date("H");

if($time < "0" && $time > "6") {
echo "Message 1";
} elseif($time < "6" && $time > "12") {
echo "Message 4";
} elseif($time < "12" && $time > "6") {
echo "Message 4";
} elseif($time < "18" && $time > "0") {
echo "Message 4";
}

?>

That is just something i quickly knocked up but should work fine.

PartyRing
28-08-2007, 06:41 PM
Doesn't work for me.
This is really annoying ;[

Drompo
28-08-2007, 06:49 PM
<?php
$time = date("H");

if($time >= "0" && $time < "6") {
echo "Message 1";
} elseif($time >= "6" && $time < "12") {
echo "Message 2";
} elseif($time >= "12" && $time < "18") {
echo "Message 3";
} elseif($time >= "18" && $time < "24") {
echo "Message 4";
}

?>

Sorry, My Dodgy Code.
That will work.

PartyRing
28-08-2007, 07:21 PM
Thanks so much!
Can i ask one more thing, if i wanted it to display an image instead of text, what would the code be?

Drompo
28-08-2007, 07:28 PM
echo "<img src='IMAGEURL'>";

PartyRing
28-08-2007, 07:32 PM
Ahh

I was using " instead of '

Thanks so much! :]

Want to hide these adverts? Register an account for free!