Give help. Get help.

  • # July 10, 2009 at 6:43 pm

    Hello everybody!

    You know these CSS-style-switchers where you can click on a daylight and nighttime style? I wanted to have a page where the switching between day.css and night.css happens automatically depending on what time it is. It’s my first PHP, so please laugh but don’t post your laughing :)

    I created a style.php where the intelligent magic happens:

    < ?php $time = $_SERVER['REQUEST_TIME']; $fluxcapacitator = date("H", $date); if ($fluxcapacitator >= 6 AND $fluxcapacitator < = 18) { echo "“;

    else {
    echo ““;


    I know it is very simple. It loads day.css in the time between 6 am and 6 pm. The country I live in is as big as the Neverland Range, so it fits perfectly to what I wanted. But there is some fine stuff like timezone und sunset functions in PHP I still cannot cope with.

    This style.php will be included in the main file daynight.php:

    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

    Day and Night

    < ?php @include("style.php"); ?>

    This is a test. If it is nighttime, the text will be displayed white on black, otherwise black on white.

    And there are day.css and night.css waiting to be called.

    And what can I say! I works! At least 50%, I have to wait now until it’s 6:01 a.m. tomorrrow morning and see if the page becomes white! PHPeeing rules!

    May be someone detects room for improvement?

    Good night!

    Me -> :D
    PHP -> :lol:

    # July 10, 2009 at 8:16 pm

    hey awesome :D thx for posting… you know you could set the time to be in like say 5 mins or something – would save you waiting… ;) or change your computer clock… :)

    # July 11, 2009 at 3:45 am

    Yeah Rob I know, but it is not the same :) Honestly, I changed the if-condition from 6 to 1 for a preview. It worked goog last night, today it displays the night.css though it is 9:45 am. :( I have to revise my code.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.