Hi,
Here is a simple-ish PHP implementation that will allow the
cookie-stored CSS theme to be accessed throughout the site, like so:
Put the folling code in a file (I'd call it cookie.php):
--- BEGIN ---
<?php
if (!empty($settheme)) {
$theme = $settheme;
setTheme();
} elseif (!empty($_COOKIE['theme'])) {
$theme = $_COOKIE['theme'];
} elseif (!empty($killcookie)) {
killCookie();
}
function setTheme() {
global $theme;
setcookie('theme',$theme,time()+2678400,'/','thesmartass.info');
}
function getTheme() {
global $theme;
$default_theme = "css.css";
$css_dir = "./css/"; // trailing slash is important.
$css_path = "cas/"; // here too.
$css_prefix = "css";
$css_suffix = ".css";
if (!empty($theme)) {
$cssfile = $css_prefix.$theme.$css_suffix;
if (!file_exists($css_dir.$cssfile)) {
$cssfile = $default_theme;
}
} else {
$cssfile = $default_theme;
}
return $css_path.$cssfile;
}
function killCookie() {
setcookie('theme','',time()-2678400);
}
?>
--- END ---
Now, at the top of each page (which needs to be php passed) before any
HTML is output, you should add:
<?php include("cookie.php"); ?>
Replace your CSS link with:
<link rel="stylesheet" type="text/css" href="<?php echo getTheme();
?>">
And the CSS links should be:
<a href="<?php echo $PHP_SELF; ?>?settheme=1">1</a> (etc...)
And if you'd like to create a link to clear theme cookies, add
something like:
<a href="<?php echo $PHP_SELF; ?>?killcookie=1">Clear Themes</a>
Try it out and let me know if you have any feedback about it, as there
are a number of minor changes that can be made to alter it's
operation.
As for the reloading the contents of the frame, the easiest way to do
that, is rather than just loading the contents of a frame using the
traditional 'target=' method, write a simple handler:
<?php
if (empty($page)) {
$page = "links"
}
?>
<iframe [...] src="/<?php echo $page; ?>.php"></iframe>
This way, your News link changes to:
<a href="index.php?page=news">News</a>
It means the main page has to reload, but it also makes the content of
that page linkable within the frameset.
Furthermore, you can add a Javascript to force the page to be loaded
in the frameset if it is loaded on it's own. This is especially handy
when you consider that your content may well be indexed on search
engines without the frameset context.
I hope this helps, let me know if you have any problems. I haven't run
this code specifically, but have written similar code many times in
the past, and that code did pass a basic syntax checker.
Regards,
sycophant-ga |