Jump to content

[SOLVED] Time controlled images, i.e. sunrise.jpg if time is between 6am and 11am


deed02392

Recommended Posts

Hi, I'm looking to have a php script which echoes the html tags for an image depending upon the time. I played around with an if statement which is as follows:

 

	<?php

if (time < 11)

{ ?>

 <img src="image/main/sunrise.jpg" alt="Good morning." width="599" height="488" hspace="30" align="middle" border="4"/>

<?php }

else if (time < 18)

{ ?>

<img src="image/main/day.jpg" alt="Good afternoon." width="599" height="488" hspace="30" align="middle" border="4"/>

<?php }

else if (time < 10)

{ ?>

<img src="image/main/evening.jpg" alt="Good evening." width="599" height="488" hspace="30" align="middle" border="4"/>

<?php } ?>

 

But it just seems to display sunrise despite the fact it is evening now. Also, I'm not sure if this function really works like this? I think this can be done with javascript, but i'd really like to do it in PHP as that means no worries about browser incompatibilities. Thanks in advanced!

make it easier

 

<font size="4">
<script language=javascript>
<!--
function greeting() {
Now = new Date()
Hour = Now.getHours();
if (Hour < 5)
msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30 

align=middle border=4/>"
else if(Hour <12)
msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30align=middle 

border=4/>"
else if(Hour < 18)
msg ="<img src=image/main/day.jpg alt=Good afternoon. width=599 height=488 hspace=30 align=middle 

border=4/>"
else if (Hour < 24)
msg ="<img src=image/main/evening.jpg alt=Good evening. width=599 height=488 hspace=30 

align=middle border=4/>"
return( msg )
}
document.write(greeting())
//-->
</script>
</font>

 

works and tested enjoy :P

 

mike

thats cause i made a mistake lol :P

 

some of the coding jumped down to another row as i copied it from my old code editor so i've put the code again and then a zip with the source code in that i just tested here and it worked saved and all

 

<html><head><title></title></head><body>
<font size="4">
<script language=javascript>
<!--
function greeting() {
Now = new Date()
Hour = Now.getHours();
if (Hour < 5)
msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30 align=middle border=4/>"
else if(Hour <12)
msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30 align=middle border=4/>"
else if(Hour < 18)
msg ="<img src=image/main/day.jpg alt=Good afternoon. width=599 height=488 hspace=30 align=middle border=4/>"
else if (Hour < 24)
msg ="<img src=image/main/evening.jpg alt=Good evening. width=599 height=488 hspace=30 align=middle border=4/>"
return( msg )
}
document.write(greeting())
//-->
</script>
</font>

 

[attachment deleted by admin]

Thank you very much for that one. The PHP one I had was working but of course was only basing the image on the server time, not the local visitor time. This javascript version is much better as I have frequent visitors from across the globe to my website, so server time doesn't suffice :P Thanks a lot!

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.