I use an IP to location database to determine the visitor's approximate latitude and longitude and then serve them a day or night color scheme based on whether it is before civil dawn or dusk. I've had problems when not specifying the timezone, specifically a 1 hour error, so I use GMT.
<?php
date_default_timezone_set("GMT");
function scheme() {
$sunrise = date_sunrise(time(), SUNFUNCS_RET_DOUBLE, $latitude, $longitude, 96, 0);
$sunset = date_sunset(time(), SUNFUNCS_RET_DOUBLE, $latitude, $longitude, 96, 0);
$now = date("H") + date("i") / 60 + date("s") / 3600;
if ($sunrise < $sunset)
if (($now > $sunrise) && ($now < $sunset)) return "day";
else return "night";
else
if (($now > $sunrise) || ($now < $sunset)) return "day";
else return "night";
}
?>