re style switcher, I got a really good script of the internet but unfortunately can't remember where from.
This switcher works with session and/or cookies which allow the chosen style to stick from page to page so say if the user selects what style they want on one page, when they navigate through the site, the style they've chosen is kept in a session or a cookie.
The code was something like this:
this should be saved as a include called style_array.php
<?
$styleSheets = array();
// Define your stylesheets (you can ad as many as you want here just increment the array index)
$styleSheets[0]["title"]='default';
$styleSheets[0]["sheet"]='<link href="default.css" rel="stylesheet" type="text/css" />';
$styleSheets[1]["title"]='alternate';
$styleSheets[1]["sheet"]='<link href="alternate.css" rel="alternate stylesheet" type="text/css" />';
// Set the style that the user will see on their first visit to the site
$defaultStyleSheet=0;
// this looks if the user has selected a stylesheet (in a cookie or in the session)
// and if nothing is found return the default style set above
if(!isset($_COOKIE["STYLE"])){
if(isset($_SESSION["STYLE"])){
echo $styleSheets[$_SESSION["STYLE"]]["sheet"];
}else{
echo $styleSheets[$defaultStyleSheet]["sheet"];
}
}else{
echo $styleSheets[$_COOKIE["STYLE"]]["sheet"];
}
?>
The second part of this is the actual switcher:
this should be saved as a include called style_switcher.php
<?
// Set a cookie for one year on the viewer's machine (can be reduced obviously...)
//with the chosen stylesheet info
if(isset($_REQUEST["SETSTYLE"])){
if(setcookie("testcookie",true)){
setcookie("STYLE",$_REQUEST["SETSTYLE"],time()+31622400,"/");
}else{
$_SESSION["STYLE"]=$_REQUEST["SETSTYLE"];
}
}
// Now just send the user back to the page they were
header("Location: ".$_SERVER["HTTP_REFERER"]);
?>
Now the last bit is in your html, instead of your normal <link> or @import, add this:
(this should be added in every page you would like the switcher to operate)
<?
include('script/style_array.php');
?>
This will write the <link> tag for the stylesheet.
Now the last bit you need are the links for user to pick a style, this goes like this:
<a href="http://yoursite.com/style_switcher.php?SETSTYLE=0">default</a>version<br />
<a href="http://yoursite.com/style_switcher.php?SETSTYLE=1">alternate</a> version
Et Voila!
So in brief, you should have 2 includes style_array.php and style_switcher.php and then it's just a matter of adding the bit in your (x)html.
I hope this is clear enough, if not, give me a shout and i'll help you
Olivier