Routing the Request: A No-Javascript CSS Style Switcher
Posted by: Jeffrey Olchovy
View the last three entries in Taming the Wild Wild Web for the necessary markup and code that is required to get our no-Javascript CSS style switcher up and running.
After you have that information down, we still need to construct the request router which will swap the alternate stylesheet for the current style sheet via our on-page trigger. In our example, this trigger is the link located in the page’s footer. Notice that it points to a PHP file.
Inside of this file is our request router and it contains the following:
<?php
session_start();
switch ($_SESSION['style']) {
case ‘default’:
$_SESSION['style']=’alt’;
break;
case ‘alt’:
$_SESSION['style']=’default’;
break;
}
session_write_close();
header(’location: http://www.flexiblephilosophy.com\’.Arra…['page']);
?>
By reading the session variables set via the Web page itself, we can determine which page makes the request for the new stylesheet and which version of the page style is to be served.
Once our output is determined, we simple close out our PHP session for writing (we don’t want any data getting lost), and redirect our user back to the page which made the request.
That concludes our tutorial on a no-Javascript CSS style switcher.
You can view the live example at flexiblephilosophy.com.
The complete code can be viewed from the following links:


