Previous Thread
Next Thread
Print Thread
Hop To
Joined: Mar 2008
Posts: 262
enthusiast
enthusiast
Joined: Mar 2008
Posts: 262
Was wondering if anyone had a quick and dirty way to change a image based on time of day. I have a image that we have a dark and light version of that we use in the top left corner of our site. We would like to have it change based on night and day.


Ian
http://www.firstgenmc.com/ubbthreads

"Experience is a hard teacher because she gives the test first, the lesson afterwords."
Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
in your header include

PHP Code

<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) { ?>
<img src="http://yoursite.com/path/to/image/beforenoon.jpg" />
<?php } else { ?>
<img src="http://yoursite.com/path/to/image/afternoon.jpg" />
<?php } ?>


for example

or

PHP Code

<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo '<img src="http://yoursite.com/path/to/image/beforenoon.jpg" />';
} else {
echo '<img src="http://yoursite.com/path/to/image/afternoon.jpg" />';
} 
?>


Joined: Mar 2008
Posts: 262
enthusiast
enthusiast
Joined: Mar 2008
Posts: 262
Hmm Not sure how I would changes this
Code
<a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255"></a>
to include that php code...


Ian
http://www.firstgenmc.com/ubbthreads

"Experience is a hard teacher because she gives the test first, the lesson afterwords."
Joined: Jun 2006
Posts: 16,299
Likes: 116
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,299
Likes: 116
PHP Code


<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo '<a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255" /></a>';
} else {
echo '<a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255" /></a>';
} 
?>




I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
If you were using SD's second block of code - you would simply drop the entire string that you posted into this bit...

Code
echo '';

...although I would have thought that if $hr > 12 it would be the afternoon period.

Is that right SD?


Last edited by driv; 01/21/2012 4:34 PM. Reason: Giz beat me to it....
Joined: Mar 2008
Posts: 262
enthusiast
enthusiast
Joined: Mar 2008
Posts: 262
So I would just replace the line I have in the middle of other code with the <?php....


Ian
http://www.firstgenmc.com/ubbthreads

"Experience is a hard teacher because she gives the test first, the lesson afterwords."
Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
Yes, the main page is php enabled (ubbthreads.php), so you just need the <?php and ?> tags to tell the php engine to do its thing.

(As opposed to just parsing regular text or HTML.)

Joined: Jan 2004
Posts: 2,474
Likes: 3
D
Pooh-Bah
Pooh-Bah
D Offline
Joined: Jan 2004
Posts: 2,474
Likes: 3
I just popped SDs code into my default header and it worked just fine... smile
PHP Code


<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo 'night';
} else {
echo 'day';
} 
?>



Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
yup, i just had afternoon switched.. but you get the idea wink

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
i do the same thing in my header logo to swap in a different logo based upon holidays ( halloween, christmas, july 4 etc )

it can do even more, if you just imagine..

wink


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
Is UBB.threads still going?
by Aaron101 - 04/01/2022 8:18 AM
Who's Online Now
1 members (Ruben), 1,248 guests, and 268 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)