Zeitgesteuertes PHP CSS Script 29-03-24/17:01

Zeitgesteuertes CSS via PHP

Eine kleine Spielerei von früher. Für eine meiner Seiten hatte ich damals einen einfachen Weg gesucht das Stylesheet dynamisch, je nach Tageszeit, zu wechseln.
In Aktion sehen kann man das Script auf folgender Seite: http://tm.kickedbyconsole.net/

Das recht simple Schnippsel dafür:

<?php

/*
Script: CSStimes
Author: itsjustm3
Site: itsjustm3.de
*/

$time = date("H");

// Angabe welches Style zu welcher Zeit aktiv wird.
if(!isset($_GET['mood'])) {
    if($time >= '08' and $time < '22') {
        $css = 'style.css';
    } elseif($time >= '22' and $time < '23') {
        $css = 'style2.css';
    } elseif($time >= '23' and $time < '24') {
        $css = 'style3.css';
    } elseif($time >= '00' and $time < '06') {
        $css = 'style4.css';
    } elseif($time >= '06' and $time < '07') {
        $css = 'style3.css';
    } elseif($time >= '08' and $time < '08') {
        $css = 'style2.css';
    } else {
        $css = 'style.css';
    }
} else {
    $moods = array('style', 'style2', 'style3', 'style4');

    if($_GET['mood'] and in_array($_GET['mood'], $moods)) {
        $css = '' . $_GET['mood'] . '.css';
    } else {
        $error = TRUE;
        echo 'You have specified an invalid mood.';
    }
}
?>

Dann natürlich noch die Variable in den CSS Header:

<?php echo $css; ?>

 



S P A M B O X !