Hello All,
This is the last bit of code I need working for a client website, and if I can get this working, then I can sign off on it...so any help would be greatly appreciated.
I'm going to try and break this down as much as I can.
What I am trying to do is get the page to load a css file (season of the year) based on a date (this works), as well, I want the user to be able to click links at the top of the page and manually change the season (this works).
I want the season to stay active while the user browses the site, and then default back to the date css, when they return later...(this doesn't work)
I have 3 files.
top.php
index.php
bottom.php
The index.php (content) uses includes to build the pages (top/bottom).
Now, in top.php I have the following code:
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
$date = date("n");
if (!isset($_GET['css'])) {
if ($date >= 4 && $date <= 5 || $css == 'spring'){ ?>
<link rel="stylesheet" href="/_stylesheets/spring.css" type="text/css" media="screen" />
<? } 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') { ?>
<link rel="stylesheet" href="/_stylesheets/autumn.css" type="text/css" media="screen" />
<? } elseif ($date >= 11 && $date <= 3 || $css == 'winter') { ?>
<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>
<body>
<div id="wrapper">
<div id="wrapper-content">
<div id="header">
<div class="header-h"></div>
<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>
In the index file I have the following code:
Code:
<?PHP
session_start();
$section='community';
include('../_includes/top.php');
print $_SESSION['css'];
?>
<div id="content">
<div id="content-wrapper">
<div id="content-info">
<div id="content-title"><h1>Engage, Inspire...</h1></div>
<div id="content-image-community"><span>Community Image</span></div>
</div>
<div id="content-links"><?php include("links.php"); ?></div>
<div id="content-links-external">
<ul class="content-links">
<li></li>
</ul>
</div>
</div>
</div>
<?PHP
include('../_includes/bottom.php');
?>
And the bottom.php simply finishes the page.
If you take a look at the top.php file you'll see that I have some PHP that loads a CSS file based on either the date, or the variable set by the user.
Below that in the same file you see some links that send variables such as "?css=spring".
So what seems to be happening is that while the variable is getting passed, and apparently saved, the code checking the variables to override the date isn't seeing it, and it's defaulting back every time I change to a new page.
I was e-mailed the following code.
< 1. // so you dont get $_SESSION['css'] set to an empty value when $_GET['css'] isn't set
2. if (isset($_GET['css'])) {
3. if (in_array($_GET['css'], array('spring', 'summer', 'autumn', 'winter'))) {
4. // set $_SESSION['css'] ONLY if $_GET['css'] is equal to one of your predifined values
5. $_SESSION["css"] = ($_GET['css']);
6. }
7. }
8.
9. //...
10. //...
11. //....and the css include conditions
12.
13. if ($_GET['css']): ?>
14. // set css according to $_GET['css']
15. <?php elseif($_SESSION['css']):
16. // set css according to $_SESSION['css']
17. <?php else: ?>
18. // set css according to date
19. <?php endif: ?>
20.
But, it doesn't appear to be coded correctly so it doesn't work.
To get a better idea of what I mean, please go here. http://www.mmmyeah.com/community/
If you look at the top, there are the four seasons of the year. Clicking on any of the seasons will pass the variable, and it should show the correct variable in the box above the title (this is just to test), and the image will change.
If you then click on "more..." in the middle, it'll take you to a new page, the right season will still be there, but the image will have defaulted back to "summer" (you can click the season again to change it).
Can anyone look over my code and see if they can get why it's not passing the variable to the correct place, as well as making sure all my code is correct.
Thanks,
Jeff