I am looking for a script that changes, images based on the time on the server. So at 12:00 its imageA then at 3:30 its imageB and so on. has anyone seen or used a script like this?
| SitePoint Sponsor |
I am looking for a script that changes, images based on the time on the server. So at 12:00 its imageA then at 3:30 its imageB and so on. has anyone seen or used a script like this?





Which serverside language can you use? php, asp or something else - I doubt Javascript would be able to handle this? If you know which serverside language you can ask a mod to move this thread in the appropriate forum where more people would be able to help you out.
Dan G
Marketing Strategist & Consultant





The appropriate Forum would be in this case: PHPask a mod to move this thread in the appropriate forum where more people would be able to help you out
Or you might be allowed to ask this question here (never visit this subforum of Sitepoint): Scripts and Online Services
Dan G
Marketing Strategist & Consultant
^^ I guess thats what I get for skimming and not reading.
Could a mod move this thread to the php section.
█ FreelanceDaddy - freelancer's personal advisor
█ Guide and advice for freelancers starting their career
█ Over 1000 projects posted on freelance markets every day
█ One-stop resource for online freelancing


First you need to decide how to format the time. Let's keep it simple and do 0000-2359 (midnight through 11:59pm). So we'll get the current time in that format:
Now that we have $currentTime as a string of '0000' - '2359' we can pick an image. Best and easiest way would be to create an array of starting times for an image to appear (with the ending time being the next startTime). Here's what I meanPHP Code:$currentTime = date('Hi');
Basically that defines 4 images. Midnight to 3:29am is image1, 3:30am to 6:59am is image2, 7:00am to 4:59pm is image3, 5:00pm to 11:59pm is image4. Now all we need to do it iterate through the array and pick the image which our $currentTime falls into:PHP Code:$imageTimes = array(
'0000' => 'image1.gif',
'0330' => 'image2.gif',
'0700' => 'image3.gif',
'1700' => 'image4.gif'
);
This goes through each starting time in the images array and compares to the current time. If the current time is equal or greater than, it sets that image as the current. Otherwise (currentTime is before startTime) then it just stops the loop.PHP Code:foreach($imageTimes as $startTime => $imageFilename) {
if ($currentTime >= $startTime)
$displayImage = $imageFilename;
else
break;
}
echo $displayImage;
It is important that your array is in increasing order from '0000' to '2359'

or....
The ojective is to create a method of displaying different images at different times of the day.
For the purposes of this example, we are presuming the following:
1. Display a different image each hour of the day (will be
using military time - 1300 = 1:00PM)
(ie midnite to 1AM is image 1; 1 AM to 2 AM is image 2 etc)
2. image data may be gathered into an array via (a) database;
(b) perusing an image folder; (c) hard coding
Lite...Code:<?PHP ######################## # Get the array elements ######################## $array_of_image_files = array('image00.jpg','image01.jpg','image02.jpg','image03.jpg','image04.jpg','image05.jpg','image06.jpg','image07.jpg','image08.jpg','image09.jpg','image10.jpg','image11.jpg','image12.jpg','image13.jpg','image14.jpg','image15.jpg','image16.jpg','image17.jpg','image18.jpg','image19.jpg','image20.jpg','image21.jpg','image22.jpg','image23.jpg'); ################################ # display the image for the current hour # for this example we are only displaying # the image name ################################# echo $array_of_image_files[date('H')]; ?>


Except your method would require 24 images (possibly copies of the same image) and disallow rotation on smaller than 60minute intervals...

True; however, it all depends upon the goals of the creator.
Slight adjustments could allow for various time increments as well as 'adjusting' the quantity of images available from the 'pool'




FWIW, this would be very easily done in Javascript.


Not really, he said based on the time of the server; not the client.Originally Posted by UFTimmy





Originally Posted by UFTimmy
Originally Posted by c2uk
Originally Posted by ZareMedia
- Javascript would work only if you want to use the time of the client, not the server.
Dan G
Marketing Strategist & Consultant
Bookmarks