Jump to content

Image change with time


PartyRing

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/67082-image-change-with-time/
Share on other sites

Well, i imported it into my page, so that a daytime/nighttime image comes up according to the time of day.

 

I think theres either a problem with the server times, so it doesnt know what time it is, therefore goes to the default image.

OR

Its the crossover times, because at the point its sopposed to change where the > and < times are the same, it also defaults.

 

If you don't understand, please tell me and ill try and explain further  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.