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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.