foevah Posted May 5, 2009 Share Posted May 5, 2009 Hi I found this tutorial: I edited the code (see below) and when it gets t evening the evening.css stylesheet doesnt load.. I have adjusted my time locally to check - morning and afternoon work but evening doesnt it displays default.css.. Can someone tell me why evening doesnt work? <?php // Get the current hour (24-hr clock) $time = date('H'); // check to see if theme is passed in the URL and, if not, // set it based on the current hour if(!isset($_GET['theme'])) { if($time >= '04' and $time < '12') { $css = 'css/morning.css'; } elseif($time >= '12' and $time < '19') { $css = 'css/afternoon.css'; } elseif($time >= '19' and $time < '04') { $css = 'css/evening.css'; } else { $css = 'css/default.css'; } } else { // if the theme is passed in the URL, specify a list of // valid theme names $themes = array('morning', 'afternoon', 'evening'); // if the theme is passed in the URL and the theme name // is in the $themes array, set the theme; otherwise, throw an error if($_GET['theme'] and in_array($_GET['theme'], $themes)) { $css = 'css/' . $_GET['theme'] . '.css'; } else { $error = TRUE; echo 'You have specified an invalid theme.'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156908-solved-time-based-css-style-switcher-doesnt-work/ Share on other sites More sharing options...
RussellReal Posted May 5, 2009 Share Posted May 5, 2009 idk but try this: <?php $time = date('G'); if (in_array($time,range(4,11))) $theme = 'morning'; elseif (in_array($time,range(12,18))) $theme = 'afternoon'; elseif (in_array($time,array(19,20,21,22,23,0,1,2,3))) $theme = 'evening'; else $theme = 'default'; $css = 'css/'.$theme.'.css'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156908-solved-time-based-css-style-switcher-doesnt-work/#findComment-826555 Share on other sites More sharing options...
foevah Posted May 5, 2009 Author Share Posted May 5, 2009 hi thanks for the quick response.. it seems to work on all 3 now. This code is much simplier. The old code let me type this: test.com/?theme=evening and i could preview a theme like that.. this doesnt work with your new code is this because you took out the !isset ? Quote Link to comment https://forums.phpfreaks.com/topic/156908-solved-time-based-css-style-switcher-doesnt-work/#findComment-826559 Share on other sites More sharing options...
foevah Posted May 5, 2009 Author Share Posted May 5, 2009 cool i managed to put the !isset back in now ?theme=morning works Quote Link to comment https://forums.phpfreaks.com/topic/156908-solved-time-based-css-style-switcher-doesnt-work/#findComment-826574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.