View Full Version : How to make a style switcher.......

10-22-2003, 09:55 PM
This question has been asked very often so here is a tutorial.....

Okay, first off you're going to need a drop down menu box....

<form action="switchstyle.php" method="POST">
<select name="styles">
<option value="Blue">Blue</option>
<option value="Green">Green</option>
<option value="Red">Red</option>
<input type="submit" value="Go!">
Of course you can add as many styles as you would like, but I'm just doing Blue, Green, and Red for examples...

Now for switchstyle.php

/*What this does is sets a cookie with the value that the select box had when Go! was clicked and redirects the browser to back to your homepage where the stylesheet will be change*/
Header("Location: http://www.yourdomain.com/index.php");
$value = $_POST['styles'];

No for your page where the style is going to be changed...

/*This checks to see if a cookie has been set (from switchstyle.php) and if it is, it sets the variable $sheet to what the value of the cookie is.css*/
$sheet = $_COOKIE['stylesheet'].'.css';
$sheet = "Blue.css";
echo '<link rel="stylesheet" type="text/css" href="'.$sheet.'">';
/*Here Blue.css is the default style sheet. If another isset, then that will be the stylesheet*/

Now you will obviously have to make the stylesheets yourself. You can change the values on the drop down box. For instance, if you have Green, you need to have a Green.css in this same directory.

Hope this helps....

Any questions or comments, post back here.....


10-23-2003, 02:19 AM
I can feel some criticism coming on from Spookster & Nightfire....:p

10-23-2003, 03:28 PM
I ain't sayin a word :D ALthough I was typing something yesterday and thought "bah, forget it" :D lol

11-05-2003, 11:53 PM
Is there an easy way to include an SSI into the style switch? Like if i wanted to change the header or sidebar to match the new style set?

Also, how could I carry this over to every page on the site, or is that implied with the script?

11-06-2003, 01:08 AM
I doubt you can do this with SSI.