Page 1 of 1

Image Directory Used According to Time of Day

Posted: Sat Jan 01, 2011 1:33 pm
by hungry_to_learn
PHP noob here...
I want my website to display a light blue theme during daytime browsing, and a dark gey theme during night browsing. I have generic code to discriminate for time based display, but I'm stuggling with how to indicate how to choose the appropriate directory, say, "day" for day images, and "night" for night images.

Both sets of image files will be named verbatim, just reside in different directories, and be accessed during differrent times of the day.

How do I indicate which folder to pull files from based on the time variable of "$h"?

Any help would be greatly appreciated ;o)

***** PLEASE USE THE PHP CODE TAG *****

Code: Select all

<?php
$h = date('G'); //set variable $h to the hour of the day

if ($h < 7) $img = 'fish.gif';
elseif ($h < 17) $img = 'images/frog.gif';
else $img = 'potato.gif';

echo '<img src="',$img,'" width="200" height="200" border="0" alt="Time Senstive Picture Display" />'; //display the appropriate image according to timestamp
?>

Re: Image Directory Used According to Time of Day

Posted: Sun Jan 02, 2011 3:30 am
by Zyxist
A part of code from my home page which uses the same trick:

Code: Select all

$time = time();	

$sunset = date_sunset($time, SUNFUNCS_RET_TIMESTAMP, $refLatitude, $refLongtitude, $refZenith, 0);
$sunrise = date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $refLatitude, $refLongtitude, $refZenith, 0);
		
if($time < $sunrise || $time > $sunset)
{
	$directoryPath = '/design/night/';
}
else
{
	$directoryPath = '/design/day/';
}

// ....

echo '<link rel="stylesheet" href="'.$directoryPath.'style.css" type="text/css" />';
echo '<img src="'.$directoryPath.'image.png" alt="foo" />';

Re: Image Directory Used According to Time of Day

Posted: Wed Jan 05, 2011 2:10 pm
by hungry_to_learn
Thank you so much for your response - I really appreaciate your help!