http://jerriko.net/template_change.php
that's the working example. hurry up and check it out =D cause it's not hosted on my server. and it's in the root dir. guy's gonna be pissed =D.
here are the files i used
-- temlate_change.php - name of this one doesnt matter
PHP Code:
<?
// if $_GET['a'] equals 'change' then set $form, else set $form to empty.
if ($_GET['a'] == 'change')
{
$form = '<form action="change.php" method="post">
<SELECT name="template">
<option value="default">default</option>
<option value="1">template 1</option>
<option value="2">template 2</option>
</SELECT>
<input type="submit" value="choose" /></form>';
}else{
$form = '';
}
// define valid templates
$templates = array('1' => 'template1','2' => 'template2');
// if cookie exists and the key exists in $templates array then set $cssfile. else make $cssfile to default
if (isset($_COOKIE['template']) && array_key_exists($_COOKIE['template'],$templates))
{
$cssfile = $templates[$_COOKIE['template']];
}else{
$cssfile = 'default';
}
?>
<html>
<head>
<title>testin css</title>
<link rel="stylesheet" type="text/css" href="<?=$cssfile?>.css">
</head>
<body>
<table width="200" height="200" class="table">
<tr>
<td>this is a table</td>
</tr>
</table><br>
<?=$form?>
<a href="<?=$PHP_SELF?>?a=change">change template</a>
</body>
</html>
------------------------------
-- change.php - this one does the changing. it must be that name and separate file. since cookies arent applied until next page view =D u'll understand later.
PHP Code:
<?
// if $_POST['template'] exists and isnt empty then set cookie.
if (isset($_POST['template']) && $_POST['template'] != "")
{
// set cookie
setcookie('template',$_POST['template'],time()+3600*24*365);
}
// redirect
header("Location: template_change.php");
?>
then i used
-- default.css
code:--------------------------------------------------------------------------------
.table {background-color: #00eeff;}
--------------------------------------------------------------------------------
------------------
template1.css, template2.css
those have the same line as default.css
only color changes
i mean you could have a different page for the template choices. so they can preview before using and the form stays there all the time. but that's more complicated =D
goodluck