Change Color Theme With PHP – CSS Switch

by Hiroshi on June 19, 2008

in Cookies, Switch

Concept is to change the CSS file of website for user to give website new color look. It is done by creating a cookie in user’s system.
One switch file, other pages and css files are used in this example. Switch file change CSS applied at website, creates a cookie, saves it and after that redirects the page back at URL from where it was triggered.

Switcher.php Code – Setting Cookie

[UPDATE] Request variable set in switcher.php file.

<?php
$set=$_REQUEST["set"];
setcookie ('sitestyle', $set, time()+31536000);
header("Location: $HTTP_REFERER");
?>

PHP Pages Code For Style Sheets & Links

<head>
<link rel="stylesheet" type="text/css" media="screen" title="default" href="<?php echo
(!$sitestyle)?'defaultstyle':$sitestyle ?>.css">
<link rel="alternate stylesheet" type="text/css" media="screen" title="blue" href="blue.css">
<link rel="alternate stylesheet" type="text/css" media="screen" title="pink" href="pink.css">
</head>
<body>
<a href="switcher.php?set=default">Default</a><br />
<a href="switcher.php?set=blue">Blue</a><br />
<a href="switcher.php?set=pink">Pink</a>
<br />
<a href="change.php">page 1</a> &nbsp;&nbsp; <a href="change2.php">page 2</a>
</body>

PHP CSS Switcher Download

Related Posts

Previous post:

Next post: