Leading zeros cause numbers to be interpreted in octal (if possible). This won't be an issue in the example code since oct 0X == dec X, for X < 8. It will cause problems other times, so be careful.
If you find yourself writing a sequence of if statements, you should generally rewrite it using a switch or an array. In this particular case, a single if statement works best.
PHP Code:
if ($time <= 5 || $time >= 19) {
echo "images/headernight.gif";
} else {
echo "images/headerday.gif";
}
// with a switch
switch ($time) {
case 0: // FALLTHRU
case 1: // FALLTHRU
case 2: // FALLTHRU
case 3: // FALLTHRU
case 4: // FALLTHRU
case 5:
echo "images/headernight.gif";
default:
echo "images/headerday.gif";
}
// with an array
$imgs = array(
// 0-5
"images/headernight.gif", "images/headernight.gif", "images/headernight.gif",
"images/headernight.gif", "images/headernight.gif", "images/headernight.gif",
// 6-19
"images/headerday.gif", ...
);
echo $imgs[(int)$time];
JS:
Code:
hour = (new Date()).getHours();
if (hour <= 5 || 19 <= hours) {
document.getElementById('sunIndicator').src = 'images/headernight.gif';
} else {
document.getElementById('sunIndicator').src = 'images/headerday.gif';
}
Hopefully, you know better than to use a table based layout and that <td> element denotes tabular data. Even so, an <img> element is more appropriate than the background, from the look of things.

Originally Posted by
c.solomon
You have to use quotes, since what you are testing are strings, not numbers.
PHP will juggle strings to numbers when comparing with numbers, as described in comparison operators. However, using strings for comparison values will prevent problems with octal numbers I mentioned above.