crazylegsmurphy Posted July 26, 2008 Share Posted July 26, 2008 Hey Everyone, I have two questions to start off with, so I hope you don't mind helping me out. This is the last bit of stuff I need done to finish off my clients site, so it would be great to get it working. 1. PHP CSS Switcher I have tried pretty much every PHP css switcher I could find on the net, but none seemed to work...or more accurately they all failed various ways. What I need is the client wants the CSS to change based on the season the viewer is looking at the page. Not only that, but they want the user to be able to manually change the season at the top of the page and have it stay like that until the next visit. I have the following code... $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" /> <? }; ?> Which seems to work for the date (except for some reason it's only showing the "Spring.css" even though it's July). If anyone has any idea why that is.... The second part which I can't figure out is how to get this code to work with a manual switcher. My second question is, I have the following code. <?php if ($section == 'gallery-spring') { ?><li class="current">Gallery</li><?php } else { ?><li><a href="/gallery/">Gallery</a></li><?php }?> What I need is to also say, if ($section == 'gallery-spring' OR 'gallery-summer' or 'gallery-winter') When I tried using the || (or) then the link stayed active the entire time....but when I took all the extra's off it was fine... Any idea how to make it look at multiple sections? Thanks so much everyone! Jeff Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 this should be $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 $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" /> <? }; ?> Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 Hmmm, that didn't seem to work either...it's still going to the "spring.css" nope, even after the changes, it's still doing the same. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 for the date, use the numeric number for the month, as greater than and less than don't work for words try date("n"); then if would be something like if(date("n") >= 1 && date("n) <= 4) { spring } Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 Great call Blade!! That solved that! Now I just need the user to be able to do it manually (and not get overwritten by that code when they change pages), and that second question! Thanks again Blade! Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 where u have the if statements for the date add an or statment if(date..... || $user = "spring") Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 if(date..... || $user = "spring") I thought of that, the problem is that if the user clicks the link "spring" then the second it changes pages will it not re-read the code and default back to the date? I think I need to store that in a cookie/session or something until the user leaves so it won't be switching back. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 yes, u will have to save it some way Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 That's pretty much where I'm stuck.... The examples I found on the net don't seem to work all that well. I can find stuff like this... $Year =31536000 + time(); setcookie ('style', $choice, $year); header("Location: $HTTP_REFERER"); ?> but it seems like really outdated and bad code...nor did it work when I tried it. The one I did get to work (it stored the cookie) couldn't actually read the cookie back into the page for some reason thus not changing anything. Personally I would rather use a session than a cookie just in case cookies are turned off. It's also better for me because I think the users need to default back to the date chosen css file and not have a cookie keeping them stuck on the one they last picked. I'm not sure however how to do that effectively with the code I have. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 try session_start(); $_SESSION['css'] = "spring"; Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 try session_start(); $_SESSION['css'] = "spring"; Blade! That looks like it might work... How would I pass that to the pages I'm currently on again? Sorry, I am drawing a blank. Here is the link (don't blame me for the design...it wasn't me) http://www.mmmyeah.com/index1.php <ul class="seasons"> <li><a href="/_scripts/switch.php?style=spring" title="Spring">Spring</a></li> <li><a href="/_scripts/switch.php?style=summer" title="Summer">Summer</a></li> <li><a href="/_scripts/switch.php?style=autumn" title="Autumn">Autumn</a></li> <li><a href="/_scripts/switch.php?style=winter" title="Winter">Winter</a></li> </ul> This is the links I have at the top of every page (via template) Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 pass it to the pages?? Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 Well, what I mean is that the user has links along the top (as you can see on the link I posted) They need to be able to click say, "winter" and it'll pass a variable somewhere to allow the session to be "winter". Then the date code that we worked on above needs to be able to see that there is a session with the variable "winter" and keep displaying the "winter.css" file until they leave. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 yes, it passes the variable in the GET , so just save the GET as the session value Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 So...(just trying to wrap my head around things) If I have this as my links...that is sending the variable to the session correct? <ul class="seasons"> <li><a href="?css=spring" title="Spring">Spring</a></li> <li><a href="?css=summer" title="Summer">Summer</a></li> <li><a href="?css=autumn" title="Autumn">Autumn</a></li> <li><a href="?css=winter" title="Winter">Winter</a></li> </ul> From there... I'm confused as to how to capture the session... I have my PHP date code... <?php $date = date("n"); if (!isset($_GET['css'])) { if ($date >= 4 && $date <= 5){ ?> <link rel="stylesheet" href="/_stylesheets/spring.css" type="text/css" media="screen" /> <? } ?> Do I need to somehow say, "if date is... or session is "spring" { ?>spring.css I think I'm confused by this session_start(); $_SESSION['css'] = "spring"; where does that go, and do I not have to have that blank or something so the session captures the variable passed by the link? i'm a tad confused how to get it all working together. Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 I did this... <? } elseif ($date >= 6 && $date <= 8 || $css = "summer") { ?> <link rel="stylesheet" href="/_stylesheets/summer.css" type="text/css" media="screen" /> <? } elseif ($date >= 9 && $date <= 10 || $css = "autumn") { ?> And it seems to switch it to autumn...but then if I click "summer" it goes to autumn....they all go to autumn actually for some reason. crap...and it also defaults the css file back to spring...something it's right there... Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 show your full code, and echo out the session to see what is stored there Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 This is the full code... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>carraigeridge.com</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="keywords" lang="en" content="" /> <meta name="description" lang="en" content="" /> <meta name="copyright" content="" /> <meta name="robots" content="all" /> <script type="text/javascript" src="/_scripts/lightbox/prototype.js"></script> <script type="text/javascript" src="/_scripts/lightbox/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="/_scripts/lightbox/lightbox.js"></script> <script type="text/javascript" src="/_scripts/external.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="/_stylesheets/lightbox.css" /> <link rel="stylesheet" type="text/css" media="screen" href="/_stylesheets/screen.css" /> <link rel="stylesheet" type="text/css" media="print" href="/_stylesheets/print.css" /> <!--[if IE 6]> <link rel="stylesheet" type="text/css" media="screen" href="/_stylesheets/screen.css" /> <link rel="stylesheet" type="text/css" media="print" href="/_stylesheets/print-ie.css" /> <![endif]--> <?php ?> <?php $date = date("n"); if (!isset($_GET['css'])) { if ($date >= 4 && $date <= 5){ ?> <link rel="stylesheet" href="/_stylesheets/spring.css" type="text/css" media="screen" /> <? } elseif ($date >= 6 && $date <= { ?> <link rel="stylesheet" href="/_stylesheets/summer.css" type="text/css" media="screen" /> <? } elseif ($date >= 9 && $date <= 10) { ?> <link rel="stylesheet" href="/_stylesheets/autumn.css" type="text/css" media="screen" /> <? } elseif ($date >= 11 && $date <= 3) { ?> <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" /> <? }; ?> </head> If I put in the session code between the PHP tags as you had on the other page... I get Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/mmmyeahc/public_html/_includes/top.php:11) in /home/mmmyeahc/public_html/_includes/top.php on line 29 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mmmyeahc/public_html/_includes/top.php:11) in /home/mmmyeahc/public_html/_includes/top.php on line 29 Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 I think I solved my second question... <?php if ($section == 'gallery-spring' || $section == 'gallery-summer') { ?><li class="current">Gallery</li><?php } else { ?><li><a href="/gallery/">Gallery</a></li><?php }?> This works... I wonder if there is a better way to write it however.... Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 Oops... I also have this as well... The site builds two files around the middle content.... <?PHP $section='community'; include('../_includes/top.php'); ?> <div id="content-preview"> <p class="italic">Engage, Inspire...</p> <p><a class="more" href="community.php" title="community">More...</a></p> </div> <?PHP include('../_includes/bottom.php'); ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 Please click solved at the bottom, if it is solved. Or there still a problem? Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 no no...the other question is solved... The main one I'm working on is still not working. (manual css switching) The css by date is working...but not the session one. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 make sure session_start(); is at the top of everypage Quote Link to comment Share on other sites More sharing options...
crazylegsmurphy Posted July 26, 2008 Author Share Posted July 26, 2008 If I put this: <?PHP session_start(); echo "Current Session is: ".$_SESSION['css']; $section='community'; include('../_includes/top.php'); ?> <div id="content-preview"> <p class="italic">Engage, Inspire...</p> <p><a class="more" href="community.php" title="community">More...</a></p> </div> <?PHP include('../_includes/bottom.php'); ?> And then click the links sending ?css="winter" it doesn't give me a session. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 where are you setting the session? Quote Link to comment 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.