MyBB Community Forums

Full Version: Change an image by the hour!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My first post here!

Im needing to find out how I can change an image by the hour. My idea is to have 24 ish images. These will reflect the time of day cycle so say for instance a user visits the forum at midnight, the background will be a moon lit sky. If the visit mid day it will be bright and sunny. Im not sure yet on wether id like it to be the logo that changes or the background but im liking more the idea of the background

so ill probably need
a folder that contains the 24 background images
the script/plugin/html that will load the image on a timer and also maybe
update the background

I dont care if this is automatic (real time) or just when a user first logs in
no replys yet but im trying to research on how to do it . since im crap with html or java its defo an eye opener! im kinda gearing towards something ive seen ...

<img id="hrimg" src="img0.jpg">
<script type="text/javascript">
document.getElementById("hrimg").src = "img" + (new Date()).getHours() + ".jpg";
</script>


You will want images named img0.jpg through img23.jpg, twenty-four in total, for each hour, where hour 0 is midnight to 0100.


now if im heading in the wrong direction on this one could someone give me a heards up ?
i'm not a fan of javascript stuff when it comes to very basic and huge page elements...

i would naturally solve it with a php script, which is called as "img src=dayimage.php" or "background url=dayimage.php" in css...

the php script would read out the actual hour value of the time (1,2...19,20..) and read/passthru the corresponding picture out of a special "dayimages" folder...
riteeee. So time to learn php me-thinx! Closest i ever came to programming was making games in BASIC on the Amiga. Thanks for the direction TStar!
much easier than you think...

take a look at this simple html, manipulated with a small php insert.

<img src="backgrounds/<?php echo gmDate("H"); ?>.jpg">

the
<?php ... ?>
will just output the daytime hour (01,02..23,24).
the rest is static html...
the final output would then be (for example) ...
<img src="backgrounds/01.jpg">

unfortunately, mybb will not let you use these little snippets within the templates too easily, so you would need to use something like
<img src="daytimeimage.php">
, where the daytimeimage.php would work something like this:

<?php
$picturepath = "/www/htdocs/xxx/images_hours/" . gmDate("H") . ".jpg";
Header("Content-type:Image/jpeg");
readfile($picturepath);
?>

these are my 2 main methods of inserting dynamic picture sources within my website and the mybb installation..
x,x
sooo ? did you succeed ?
I havent tried yet mate! Ive switched servers and kinda lost everything. Luckily i backed up my database. Ive spent the past 3 days learning MySQL so i could import the old database after id edited it all in a text editor. (paths and folders of my install had changed once the server switched). Its up and running again . Im working on the look of it over the next 48 hours .. perfect time to try this! thanks sooo much for the info! ill post back my success !
Wow, this looks interesting and what I am also looking for - however - noob question of the week - where do I put the php file once I have it? Is it a folder on the server?
Make the PHP file and then put it in your forum root.
Or just get template conditionals plugin, and do the first one. This isn't hard.