Jump to content

Random image according to Time of Day


Recommended Posts

Hello there everybody,

 

I'm new to this forum and new to (php) coding but i have a question that i think y'all can help me with.

 

I have a portfolio website for which i had the idea to make the background images randomize when reloading to keep it more fresh looking, however!:

 

Since the website has a grayscale theme I want to influence according to the time of day:  the array's from which the images are chosen should change at certain times a day, so i can load images accordingly (use darker pictures at night and lighter pictures during the day)

 

Also, while we are at it.. i would like some code that would redirect my index page to another page during certain times of the day  (like at lunch-time, between 0300 and 0400 and of course during christmas) without me having to adjust the page!

 

The URL of my site is www.ikbenkevin.com, this is the old version, but the new one will be quite similar, except harder better faster stronger!

 

I hope someone can help me out, i have tried searching the forums but the search tool did not work, if this topic (for some reason) already exists 7 times i apologize!!

 

Big thanks for anyone willing to help out!!

 

Here are some more details:

 

number of backgrounds to change : 2 (maybe 3 incl the header)

Number of 'timezones' :      5 - 7

Expected number of backgrounds in stock:  +20 per timezone

Website layout : 

 

<div page>

big background

<div header>

redirects to header.php

</div header>

<div menu>

redirects to menu.php

</div menu>

<div body>

Now directs to div body.php

should have a changing background as well

</div body>

<div footer>

nothing fancy

</div footer>

</div page>

Link to comment
Share on other sites

I have a portfolio website for which i had the idea to make the background images randomize when reloading to keep it more fresh looking, however!:

 

Since the website has a grayscale theme I want to influence according to the time of day:  the array's from which the images are chosen should change at certain times a day, so i can load images accordingly (use darker pictures at night and lighter pictures during the day)

In your database or wherever, categorize images according to the criteria you want. Then in the code your query can pull (randomly) from images that are in some specific category.

Or you can go a more complex but more flexible route and use date and time ranges for each image then pull (randomly) from whatever is in the range.

 

I also recommend designing the randomization process so that whatever image it picks stays for a while - like an hour or so. Otherwise every page load could pull up a different image and that could be quite distracting for your users. If you're worried about the additional complexity then let me tell you that it would be a very trivial modification.

 

Also, while we are at it.. i would like some code that would redirect my index page to another page during certain times of the day  (like at lunch-time, between 0300 and 0400 and of course during christmas) without me having to adjust the page!

Stop for a lunch break? (At 3am?) A holiday? But the Internet doesn't have lunch breaks or holidays...

Link to comment
Share on other sites

@ Requinix:

 

Currently i do not have a database, nor do i know how to make query's, (i get the general idea though), and yes, i do want the image to change every time you reload the page, (they are all black and white with a red dropthrough, and they will be 'softened' accordingly, but i want to give it a 'chance-factor'). Also the 'closed for lunchtime-diversion' is one of these random easter eggs.

 

As i said before, i do not have any php coding skills, but i can manage some html and i can adjust php-scripts to some extent. I have a crude idea of how the process should look like:

 

1. go to index page:

Here, run script to send to the desired page, this should contain a script that looks at the date and time, and then redirects the page.

 

e.g.   

on sundays go to ..pages/sunday.html 

everyday between 12:30 and 13:00 go to ..pages/lunch.html

on 1st of april go to www.disneyland.com

if there are no conditions go to ../pages/index2.php

 

2. then, when you go to the main page, this should happen.

 

a script reviews the time and date and gets 2 (or 3) different backgrounds (one for the main page, one for the column and maybe the header). All 3 should be random (so no sets of 3) and should be gotten from a database or if possible it should scan folders on the server (if this would be possible it would be real easy with updating new images) and pick a random image. Also, because it is a portfolio website i might want to re-use the scripts for different pages. (so make a music themed set for the music, and a graphic set for the graphic works etc. etc. ,but this i can probably edit later by myself).

 

I think it would work best if there where 4 or 5 pointers that locate to different folders in some sort of script that works like this (i'm sorry for the crappyness)

 

<Script1>

image background=select random image from <Run script 2> and place in page(s)

</script 1>

 

<script 2>

Determine location url's:

 

If time is between 0600 and 0900 go to folder ../images/morning

if time is between 0900 and 1300 go to folder ../images/early noon

etc. etc. et.c. etc.

</script 2>

 

you could make 1 script that handles it all but i guess you could also make a small one and re-use it for the background, header and other pages. Since i'm quite the layman when it comes to this for me the easier (or at least most understandable) is better. I guess the idea is quite possible, but i'm just not experienced enough in php to pull it off myself. If there is anybody out there who thinks ' 8) I can do this, cause i'm a boss' please let me know, you'll have my eternal blessing and respect!

 

I don't know if i mentioned it in my post before, but the idea is to change the background darkness according to the time of day (dark at night, light at noon, shades in between and maybe the random colorful LSD type image between 16:20 and 16:21 ;) )  My url is www.ikbenkevin.com to see the colorscheme!

 

Thnx in advance!

Link to comment
Share on other sites

I highly doubt anyone here is going to make it for you, you should set yourself off learning PHP. Also it's your portfolio hah. I recommend the book PHP & MySQL: the missing manual it's a great starter book.

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.