PHP CSS Switcher / Time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazylegsmurphy
Forum Newbie
Posts: 8
Joined: Thu Jul 24, 2008 11:21 am

PHP CSS Switcher / Time

Post by crazylegsmurphy »

Hey All,

Ok, so I have been sitting here for about 8 hours trying to find a working CSS switcher, but all the ones I have tried simply don't work.

The website I am doing needs to load a css file depending on the date range (as they are seasons of the year) so if the user shows up in winter it'll display the winter CSS.

The second part is that the user needs to be able to manually switch the season if they choose and it needs to stay like that until they leave.

I have been trying to figure out the part where they can switch it manually, but nothing is working. Some of the examples I have found bring me to a blank page, some refresh the page but do nothing more, some give me outright errors. Needless to say none of them work.

What I need it help finding or writing a css switcher/time that is current code (most of the ones I found are really old bad code). If anyone has any ideas I would greatly appreciate it.

Thanks,

Jeff
Sephirangel
Forum Commoner
Posts: 45
Joined: Tue Jul 15, 2008 1:37 pm

Re: PHP CSS Switcher / Time

Post by Sephirangel »

Which ones have you tried using so far?
Maybe use the date() function to get the month number (1-12) and using them in a switch statement? generating the css file link?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: PHP CSS Switcher / Time

Post by jayshields »

Have 4 different CSS files for each season.

Something like this for the manual CSS choice page:

Code: Select all

 
If the form has been submitted
  Create a session variable with the chosen style in it.
End if.
 
Then pseudo code for each page:

Code: Select all

 
If no session is available with a user chosen style.
   Use PHP to echo the HTML link tag including the CSS file depending on which date range a date() function call returns.
Else a session variable with a user chosen style is set.
  Use PHP to echo the HMTL link tag including the CSS file the user wants.
End if.
 
crazylegsmurphy
Forum Newbie
Posts: 8
Joined: Thu Jul 24, 2008 11:21 am

Re: PHP CSS Switcher / Time

Post by crazylegsmurphy »

Hey,

I have tried most of the ones you can find on the net by searching in PHP Css Switcher such as:

http://php.about.com/od/finishedphp1/ss ... itcher.htm
http://gr0w.com/articles/code/css_style ... ript_free/
http://www.sitepoint.com/article/css-si ... e-switcher
http://www.456bereastreet.com/archive/2 ... _switcher/
http://www.alistapart.com/articles/phpswitch/

None of them worked, but to varying degrees.

Jay, that sounds pretty much what I'm looking for. Any chance of helping me out with that a tad? I'm fairly newish with PHP so I get it, but it would help to see more what you're talking about.

Thanks!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: PHP CSS Switcher / Time

Post by jayshields »

Do you know anything about sessions or the how to use the date() function?

Try looking in the PHP manual and trying to code it yourself, post back with what you've done and I'm sure me or someone else will help you further.
crazylegsmurphy
Forum Newbie
Posts: 8
Joined: Thu Jul 24, 2008 11:21 am

Re: PHP CSS Switcher / Time

Post by crazylegsmurphy »

Code: Select all

<?php 
$date = date("F");
if (!isset($_GET['css'])) {
if ($date >= April && $date < May) { ?>
<link rel="stylesheet" href="/_stylesheets/spring.css" type="text/css" media="screen" />
<? } elseif ($date >= June && $date < August) { ?> { ?>
<link rel="stylesheet" href="/_stylesheets/summer.css" type="text/css" media="screen" />
<? } elseif ($date >= September && $date < October) { ?> { ?>
<link rel="stylesheet" href="/_stylesheets/autumn.css" type="text/css" media="screen" />
<? } elseif ($date >= November && $date < March) { ?>
<link rel="stylesheet" href="/_stylesheets/winter.css" type="text/css" media="screen" />
<? } else { ?>
<link rel="stylesheet" href="/_stylesheets/screen.css" type="text/css" media="screen" />
<? }; 
} else { ?>
<link rel="stylesheet" href="</_stylesheets/<?php echo $_GET['css']; ?>.css" type="text/css" media="screen" />
<? }; ?>
This is what I was able to get for the date change. Of course for some reason it's displaying the "spring.css" file even though it's July...which I can't figure out.

How to get this code to work with the manual switcher I still can't figure out.

Anyone have any ideas?

..
Post Reply